try {
context.getAttributes().put(SKIP_ITERATION_HINT, true);
Set<VisitHint> hints = EnumSet.of(VisitHint.SKIP_ITERATION);
VisitContext visitContext = VisitContext.createVisitContext(context, null, hints);
subTree.visitTree(visitContext, new VisitCallback() {
public VisitResult visit(VisitContext visitContext, UIComponent component) {
VisitResult result = VisitResult.ACCEPT;
if (component.getClientId(visitContext.getFacesContext()).equals(clientId)) {
/*
* If the client id matches up we have found our match.
*/
found.add(component);
result = VisitResult.COMPLETE;
} else if (component instanceof UIForm) {
/*
* If the component is a UIForm and it is prepending its id
* then we can short circuit out of here if the the client
* id of the component we are trying to find does not begin
* with the id of the UIForm.
*/
UIForm form = (UIForm) component;
if (form.isPrependId() && !clientId.startsWith(form.getClientId(visitContext.getFacesContext()))) {
result = VisitResult.REJECT;
}
} else if (component instanceof NamingContainer) {
/*
* If the component is a naming container then assume it is
* prepending its id so if our client id we are looking for
* does not start with the naming container id we can skip
* visiting this tree.
*/
if (!clientId.startsWith(component.getClientId(visitContext.getFacesContext()))) {
result = VisitResult.REJECT;
}
}
return result;