Java 如何将f:selectItem的可见性设置为p:selectOneRadio?
我有一个p:SelectOneRadio,在我的表单中有4个选项。 我想根据用户配置文件(存储在会话中),仅在一个f:SelectItem中将呈现的条件设置为false 例如:如果用户是管理员,他可以看到选项4(f:selectItem) 我已经知道怎么做了,但是组件SelectItem似乎没有属性“Rendered”,我应该用什么来做呢Java 如何将f:selectItem的可见性设置为p:selectOneRadio?,java,jsf,primefaces,Java,Jsf,Primefaces,我有一个p:SelectOneRadio,在我的表单中有4个选项。 我想根据用户配置文件(存储在会话中),仅在一个f:SelectItem中将呈现的条件设置为false 例如:如果用户是管理员,他可以看到选项4(f:selectItem) 我已经知道怎么做了,但是组件SelectItem似乎没有属性“Rendered”,我应该用什么来做呢 <p:selectOneRadio id="rdnNivel" valu
<p:selectOneRadio id="rdnNivel"
value="#{empresaController.selected.nivel}" layout="custom"
required="true"
requiredMessage="Select one option">
<f:selectItem itemLabel="Option 1" itemValue="1" />
<f:selectItem itemLabel="Option 2" itemValue="2" />
<f:selectItem itemLabel="Option 3" itemValue="3" />
<f:selectItem itemLabel="Option 4" itemValue="4"/>
谢谢你!
多亏@perissef,问题才得以解决 豆子:
private List niveis=new ArrayList();
公共集合getNiveis(){
if(niveis.isEmpty()){
此.niveis.add(新选择项(1,“选项1”);
此.niveis.add(新选择项(2,“选项2”);
此.niveis.add(新选择项(3,“选项3”);
如果(FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get(“perfil”)=“ADM”){
此.niveis.add(新选择项(4,“选项4”);
}
}
返回niveis;
}
xhtml,自定义primefaces选择器Radio:
<p:selectOneRadio id="rdnNivel"
value="#{empresaController.selected.nivel}" layout="custom"
required="true">
<f:selectItems value="#{empresaController.niveis}" />
</p:selectOneRadio>
<p:panelGrid columns="2">
<p:radioButton id="opt1" for="rdnNivel" itemIndex="0" />
<h:outputLabel for="opt1" value=" Nivel 1" />
<p:radioButton id="opt2" for="rdnNivel" itemIndex="1" />
<h:outputLabel for="opt2" value=" Nivel 2" />
<p:radioButton id="opt3" for="rdnNivel" itemIndex="2" />
<h:outputLabel for="opt3" value=" Nivel 3" />
<p:radioButton id="opt4" for="rdnNivel" itemIndex="3"
rendered="#{(sessionScope['perfil'] == 'ADM')}" />
<h:outputLabel for="opt4" value=" Nivel 4"
rendered="#{(sessionScope['perfil'] == 'ADM')}" />
</p:panelGrid>
您应该使用f:selectItems来代替可能的重复项,并在背景栏中检索项目列表,这也是一个好方法!我也在读“可能的副本”,谢谢@perissf,它现在正在工作。
<p:selectOneRadio id="rdnNivel"
value="#{empresaController.selected.nivel}" layout="custom"
required="true">
<f:selectItems value="#{empresaController.niveis}" />
</p:selectOneRadio>
<p:panelGrid columns="2">
<p:radioButton id="opt1" for="rdnNivel" itemIndex="0" />
<h:outputLabel for="opt1" value=" Nivel 1" />
<p:radioButton id="opt2" for="rdnNivel" itemIndex="1" />
<h:outputLabel for="opt2" value=" Nivel 2" />
<p:radioButton id="opt3" for="rdnNivel" itemIndex="2" />
<h:outputLabel for="opt3" value=" Nivel 3" />
<p:radioButton id="opt4" for="rdnNivel" itemIndex="3"
rendered="#{(sessionScope['perfil'] == 'ADM')}" />
<h:outputLabel for="opt4" value=" Nivel 4"
rendered="#{(sessionScope['perfil'] == 'ADM')}" />
</p:panelGrid>