0

In JSF a UIViewRoot is created for our JSF page. When we traverse it, which algorithum is used to traverse it?

Gaurav Jeswani
  • 4,410
  • 6
  • 26
  • 47

1 Answers1

1

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.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555