How do you conditionally hide/show or enable/disable menuitems in PrimeFaces?

前端 未结 3 1287
暗喜
暗喜 2021-01-16 02:26

I want to do the following: active o inactive a menuitem with management bean (MB), I want to use properties \"renderer\". But I don\'t Know like do it.

My code is

相关标签:
3条回答
  • 2021-01-16 02:36

    so you must change code:

    import javax.faces.bean.ManagedBean;
     import javax.faces.bean.RequestScoped;
    
    
     @ManagedBean (name = "activacionOpcionesMB")
     @RequestScoped
     public class ActivacionOpcionesMB {
    
        private boolean registrarPatio = true;
    
    
        public boolean getRegistrarPatio()
        {
            return registrarPatio;
        }
    
        public void setRegistrarPatio(boolean registrarPatio)
        {
            this.registrarPatio = registrarPatio;
        }
    
    
    
        public boolean activarItemPermisos()
        {
           if(condition)
           {
              registrarPatio = true;
           }
        else
           {
             registrarPatio = false;
           }
    
        }
     }
    

    and in your code xhtml :

    <p:menuitem id="registrarPatio" value="Registrar un Patio"
                actionListener="#{accionesRedirectMB.redireccionar('/PatioWEB/jsp/patios/registrarPatio.xhtml')}"
                icon="ui-icon-folder-collapsed" rendered="#{activacionOpcionesMB.activarItemPermisos()}"/> 
    
    0 讨论(0)
  • 2021-01-16 02:37

    While I was finding answers, I got the following:

    This my code in xhtml:

      <p:menuitem id="registrarPatio" value="Registrar un Patio"
                actionListener="#{accionesRedirectMB.redireccionar('/PatioWEB/jsp/patios/registrarPatio.xhtml')}"
                icon="ui-icon-folder-collapsed" rendered="#{activacionOpcionesMB.activarItemPermisos()}"/> 
    

    I use properties "redered", rendered="#{activacionOpcionesMB.activarItemPermisos()}", where activacionOpcionesMB.activarItemPermisos() is my MB.

    This is my MB:

    package co.com.patios.mb.util;

     import javax.faces.bean.ManagedBean;
     import javax.faces.bean.RequestScoped;
    
    
     @ManagedBean (name = "activacionOpcionesMB")
     @RequestScoped
     public class ActivacionOpcionesMB {
    
        public boolean registrarPatio = true;
    
        public void activarItemPermisos(){
           if(true){
              registrarPatio = false;
           }
        }
    
    
     }
    

    "registrarPatio" is the data that I use for active o unactive menuItem, for default it's true.

    The method activarItemPermisos() is where I active the menuItem, here I use conditional and after I assing to registrarPatio false.

    You can use "if" for validate access to the different option in their applications.

    0 讨论(0)
  • 2021-01-16 02:51

    To enable or disable (showing it all the time) you must create a boolean variable and you put it in a condition, for example:

    private boolean isDisabled = false; // with the getter and setter
    if( condition)
    {
        isDisabled = true;
    }
    else
    {
        isDisabled = false;
    }
    

    after that, you add in your page the disabled of rendered attribute:

     <p:menuitem ... disabled=#{activacionOpcionesMB.isDisabled} />
    

    But you could also put the condition in the EL line in the answer that uses 'rendered'

    0 讨论(0)
提交回复
热议问题