In JSF a UIViewRoot is created for our JSF page. When we traverse it, which algorithum is used to traverse it?
Asked
Active
Viewed 148 times
0
-
You can find that in the JSF specification document – kolossus Jul 29 '15 at 05:14
-
I tried to find that , but did not find. If you have any reference please share it with me. – Gaurav Jeswani Jul 29 '15 at 05:15
-
https://jcp.org/aboutJava/communityprocess/final/jsr314/index.html – kolossus Jul 29 '15 at 05:16
-
Thanks Kolossus, but what you have given is Portlet specification, it doesn't contains JSF specification. – Gaurav Jeswani Jul 29 '15 at 05:27
-
I'm not sure what you're looking at, but I just downloaded the files from that very link and the PDF in the zip files has "JSF 2.0 specification" in bold on it – kolossus Jul 29 '15 at 05:42
1 Answers
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