Search code examples
jsfmojarra

JSF SystemListner and dynamic user autorization setting


I was trying to implement dynamic user access level as mentioned in The earliest moment to visitTree() on fully built Component Tree? .However , I don't see the full DOM tree while parsing. While parsing I can only see the child elements of the template pages. What I'm missing?

Code snippets:

face-config.xml

<system-event-listener>
    <system-event-listener-class>com.xyz.listner.FieldDisableListener</system-event-listener-class>
    <system-event-class>javax.faces.event.PostAddToViewEvent</system-event-class>
    <source-class>javax.faces.component.UIViewRoot</source-class>
</system-event-listener>

JSF Page

<ui:composition template="/WEB-INF/templates/samplePage.xhtml">
<ui:param name="focusElement" value="frmWelcome:newProfileLink" />
<ui:define name="pageContents">
<h:form id="pendingsearchForm" styleClass="content-body">
<h:commandLink action="#{searchBean.release}" 
                id="searchcmdbtn" <<-- updated
                value="Release" 
                immediate="true"
                rendered="#{searchBean.resultFound}" >
</h:commandLink>

Listener Code

@Override
public void processEvent(SystemEvent event) throws AbortProcessingException    {
UIViewRoot root = (UIViewRoot) event.getSource();
loadUserAccessConfig();
processViewTree(root);
}
@Override
public boolean isListenerForSource(Object source) {
if (source instanceof UIViewRoot)
  return true;
return false;
}

Solution

  • I did the following change in my JSF tree parsing logic to make my code work:

    facesContext.getViewRoot().getFacetsAndChildren();