10 Replies Latest reply on Sep 10, 2009 5:13 PM by snowhite

    FacesMessages are not getting displayed

    snowhite

      Hi all,

      I have a situation where in which I need to check user access on a particular page element. For example, I have a rich:dataTable having a hyperlink in one of its columns. when user clicks on the link, I need to check the user access and should throw error message if access is denied. My code is as below

      My page:

       <h:panelGrid columns="1" id="panel1">
       <rich:messages level="ERROR"> </rich:messages>
       <rich:dataTable value="#{modulesToDisplay}" var="item" id="table">
       <rich:column sortBy="#{item.name}" >
       <f:facet name="header">Name</f:facet>
       <a4j:commandLink id="editId" actionListener="#{module1Manager.isValidAccess}" action="#module1Manager.editModule}" value="#{item.name}"
       reRender="panel1" rendered="#{module1Manager.renderEditLink}">
      
       </a4j:commandLink>
       <h:outputText id="displayId" value="#{item.name}" rendered="#{module1Manager.renderDisplayLink}" />
       </rich:column>
       <rich:column>
       <f:facet name="header">User Count</f:facet>
       <h:outputText value="#{item.moduleUserCount}"/>
       </rich:column>
      

      ActionListener method:
       public void isValidAccess(ActionEvent event){
       UIComponent component = event.getComponent();
       System.out.println("Action Listener from Id: "+component.getId());
       isValid=AccessManager.checkElementIdAccess(component.getId(), identity.getUsername());
      
       }
      

      Action Method:
       public String editModule(){
       if(isValid){
       return "edit";
       }
       else {
       FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR,"Insufficient Privileges", "Insufficient Privileges");
       FacesContext.getCurrentInstance().addMessage(null,message);
       return null;
       }
       }
      


      If user does not have access to edit functionality(hyperlink), then "Insufficient privileges" error should be displayed. It is not displaying the error message. However, if I hardcode the "isValid" variable to false, I can see the error message on the page.

      I dnt know why the error message is not showing when I set the "isValid" variable based on the database result.

      Any help is appreciated.

      Thanks.