Access ViewRoot before render response in a PhaseListener
Hi,
I'm trying to access UIComponents just before the render response phase to change some attributes of the UIComponents. Therefor I have created a PhaseListener, which is called before the render response phase. My idea was, to get the ViewRoot and iterate over it to access all UIComponents, but in the beforePhase, the ViewRoot has no children. How can I solve this problem?
Here is my PhaseListener:
publicclass SecurityPhaseListenerimplements PhaseListener{
privatestatic Log log = LogFactory.getLog(SecurityPhaseListener.class);
publicvoid afterPhase(PhaseEvent pe){
}
public PhaseId getPhaseId(){
return PhaseId.RENDER_RESPONSE;
}
publicvoid beforePhase(PhaseEvent pe){
UIViewRoot viewRoot = pe.getFacesContext().getViewRoot();
System.out.println("before render response " + viewRoot.getChildCount());// returns 0
// the following is just sample code for you to get an idea of what i want to do
// change attributes according permissions
for (Iterator iter = viewRoot.getChildren().iterator(); iter.hasNext();){
UIComponent comp = (UIComponent) iter.next();
if(compinstanceof HtmlInputText){
HtmlInputText htmlInputText = (HtmlInputText) comp;
htmlInputText.setRendered(false);
}
}
}
}

