segunda-feira, 21 de março de 2016

JSF get component by ID





public UIComponent findComponent(String id) {

UIComponent result = null;
UIComponent root = FacesContext.getCurrentInstance().getViewRoot();
if (root != null) {
result = findComponent(root, id);
}
return result;

}

private UIComponent findComponent(UIComponent root, String id) {

UIComponent result = null;
if (root.getId().equals(id))
return root;

for (UIComponent child : root.getChildren()) {
if (child.getId().equals(id)) {
result = child;
break;
}
result = findComponent(child, id);
if (result != null)
break;
}
return result;
}

Nenhum comentário:

Postar um comentário