beforePhase() of RENDER_RESPONSE,cann't find component
It was a strange problem.
In my page there is a form(id = userForm),which contains some components with their seprated id.
I register a phase Listener as follow:
public class PrintRestoreView implements PhaseListener{
public void afterPhase(PhaseEvent arg0) {
System.out.println("The phase is: "+arg0.getPhaseId());
System.out.println("ViewRoot's Children Count: " + arg0.getFacesContext().getViewRoot().getChildCount());
this.findComponent(arg0.getFacesContext().getViewRoot());
}
public void beforePhase(PhaseEvent arg0) {
System.out.println("The phase is: "+arg0.getPhaseId());
System.out.println("ViewRoot's Children Count: " + arg0.getFacesContext().getViewRoot().getChildCount());
this.findComponent(arg0.getFacesContext().getViewRoot());
}
public PhaseId getPhaseId() {
return PhaseId.RENDER_RESPONSE;
}
public void findComponent(UIViewRoot vRoot){
if (vRoot==null){
System.out.println("ViewRoot is null.");
}else
System.out.println("ViewRoot is not null.");
UIComponent comp = vRoot.findComponent("userForm:username");
if (comp==null){
System.out.println("username cann't be found.");
}else{
System.out.println("The Class of username: " + comp.getClass().getName());
}
comp = vRoot.findComponent("userForm");
if (comp==null){
System.out.println("userForm cann't be found.");
}else{
System.out.println("The Class of userForm: " + comp.getClass().getName());
}
}
}
The problem is :
After the RENDER_RESPONSE,it runs normal.It can find the component.
BUT before the RENDER_RESPONSE,the ViewRoot is not null but it has no child.
Anyone can tell me what is problem is ?
Thank u!

