0

I have a p:SelectOneRadio with 4 options in my form. I would like to set the condition Rendered to false only in one f:SelectItem, depending on user profile (stored on session)

E.g: If the user is an Administrator, he can see the option 4 (f:selectItem).

I already know how to do it, but it seems that the component SelectItem doesn't have the property "Rendered", what should i use to do that?

                    <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"/>

Thank's !

Pellizon
  • 1,365
  • 2
  • 12
  • 26

1 Answers1

0

Question solved thanks to @perissef

Bean:

private List<SelectItem> niveis = new ArrayList<SelectItem>();
public Collection<SelectItem> getNiveis() {
if (niveis.isEmpty()) {
    this.niveis.add(new SelectItem(1, "Option 1"));
    this.niveis.add(new SelectItem(2, "Option 2"));
    this.niveis.add(new SelectItem(3, "Option 3"));
    if (FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("perfil") == "ADM") {
    this.niveis.add(new SelectItem(4, "option 4"));
    }
}
return niveis;
}

xhtml, custom primefaces selectOneRadio :

<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>
Pellizon
  • 1,365
  • 2
  • 12
  • 26