* <p>This method must not return null.</p>
*/
public String getClientId(FacesContext context, UIComponent component) {
String clientId = null;
NamingContainer closestContainer = null;
UIComponent containerComponent = component;
// Search for an ancestor that is a naming container
while (null != (containerComponent =
containerComponent.getParent())) {
if (containerComponent instanceof NamingContainer) {
closestContainer = (NamingContainer) containerComponent;
break;
}
}
// If none is found, see if this is a naming container
if (null == closestContainer && component instanceof NamingContainer) {
closestContainer = (NamingContainer) component;
}
if (null != closestContainer) {
// If there is no componentId, generate one and store it
if (component.getComponentId() == null) {
// Don't call setComponentId() because it checks for
// uniqueness. No need.
clientId = closestContainer.generateClientId();
} else {
clientId = component.getComponentId();
}
// build the client side id