In JSF a UIViewRoot is created for our JSF page. When we traverse it, which algorithum is used to traverse it?
Not sure if "algorithm" is the right wording. It at least supports both iterator and visitor patterns.
Iterator goes via UIComponent#findComponent()
(click link to see extensive javadoc describing the search algorithm).
UIComponent found = someComponent.findComponent(clientIdExpression);
// ...
Visitor goes via UIComponent#visitTree()
and UIComponent#invokeOnComponent()
.
someComponent.visitTree(VisitContext.createVisitContext(FacesContext.getCurrentInstance(), Arrays.asList(clientId), null), new VisitCallback() {
@Override
public VisitResult visit(VisitContext context, UIComponent found) {
// ...
return VisitResult.COMPLETE;
}
});
someComponent.invokeOnComponent(FacesContext.getCurrentInstance(), clientId, new ContextCallback() {
@Override
public void invokeContextCallback(FacesContext context, UIComponent found) {
// ...
}
});
Either way, someComponent
can represent the UIViewRoot
itself, but it can basically be any parent component you want.