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
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()}"/>
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.
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'