Does JSF 2.0 have a built-in method for finding the client ID of another component? There are about a thousand client ID-related questions on SO and there are a lot of hack
This worked for me. I would be interested to know if it is Ok to write response like this though.
client.html
UIHelper.java
@ManagedBean(name = "UIHelper", eager = true)
@ApplicationScoped
public class UIHelper
{
public String clientId(final String id)
{
FacesContext context = FacesContext.getCurrentInstance();
UIViewRoot root = context.getViewRoot();
final UIComponent[] found = new UIComponent[1];
root.visitTree(new FullVisitContext(context), new VisitCallback()
{
@Override
public VisitResult visit(VisitContext context, UIComponent component)
{
if (component.getId().equals(id))
{
found[0] = component;
return VisitResult.COMPLETE;
}
return VisitResult.ACCEPT;
}
});
return found[0] == null ? "" : "#" + found[0].getClientId().replace(":", "\\\\:");
}
}