Good morning, JSF experts!
Let me fugure out the problem I'm trying to solve. The application has many forms. And elements in forms can be marked to require authorization of users according to 1) set of rights and their conditional combinations configured for this form element and 2) user rights loaded from db.
Solution I'm trying to develop is as follows: I implement custom component, which extends UIComponentBase
. In the form's Facelets' markup this custom component would wrap elements under authorization:
<custom:applyRights id="abc">
<p:inputText
id="inputWithRights"
value="Some placeholder..."
tabindex="0"/>
</custom:applyRights>
Then I need to modify component tree. I.e. just after the component tree is built I need to find my <custom:applyRights/>
, visit its subtree and either leave components as is, or disable them, or set setRendered( false )
etc. The concrete action taken upon a component also depends on the component's type.
Then I imlement PhaseListener
with:
@Override
public PhaseId getPhaseId() {
return PhaseId.RESTORE_VIEW;
}
In its afterPhase(PhaseEvent phaseEvent)
I get current instance of FacesContext
, UIViewRoot
, build new FullVisitContext(facesContext)
and attempt viewRoot.visitTree
.
But then only viewRoot gets visited.
What am I doing wrong? Maybe I'm trying to visitTree()
too early? Then when should it be done?
Thanks!