public static String getClientId(UIComponent component,
Renderer renderer,
FacesContext context) {
//forceId enabled?
boolean forceId = RendererUtils.getBooleanValue(JSFAttr.FORCE_ID_ATTR,
component.getAttributes().get(JSFAttr.FORCE_ID_ATTR),false);
if (forceId && component.getId() != null)
{
String clientId = component.getId();
/**
* See if there is a parent naming container. If there is ...
*/
UIComponent parentContainer = HtmlComponentUtils.findParentNamingContainer(component, false);
if (parentContainer != null)
{
if (parentContainer instanceof UIData)
{
// see if the originally supplied id should be used
boolean forceIdIndex = RendererUtils.getBooleanValue(JSFAttr.FORCE_ID_ATTR,
component.getAttributes().get(JSFAttr.FORCE_ID_INDEX_ATTR),true);
// note: user may have specifically requested that we do not add the special forceId [index] suffix
if (forceIdIndex)
{
int rowIndex = ( (UIData) parentContainer).getRowIndex();
if (rowIndex != -1) {
clientId = clientId + "[" + rowIndex + "]";
}
}
}
}
// JSF spec requires that renderer get a chance to convert the id
if (renderer != null)
{
clientId = renderer.convertClientId(context, clientId);
}
return clientId;
}
else
{
return null;
}
}
Gets the client id associated with the component. Checks the forceId
attribute of the component (if present) and uses the orginally supplied
id value if that attribute is true. Also performs the required call
to convertClientId on the Renderer argument. |