JSF change information in XHTML

Asked

Viewed 80 times

0

Good night.

I have a java/jsf application I’m having a hard time showing information in XHTML,

Well I have a SelectOneMenu to save information in the bank:

<p:selectOneMenu id="PermissaoAcesso"
    value="#{usuarioManageBean.usuario.permissaoAcesso}" required="true"
    label="PermissaoAcesso">
    <f:selectItem itemLabel="Selecione" itemValue="" />
    <f:selectItems value="#{permissaoView.permissoes}" />
    <f:validateLength minimum="1" />
    <p:ajax event="change" update="displayEquipe1" process="@this" />
    <p:ajax event="change" update="displayEquipe2" process="@this" />
</p:selectOneMenu>

He pulls the information from a class called PermissaoView:

 @PostConstruct
    public void init() {
        permissoes = new HashMap<String, String>();
        permissoes.put("Supervisor", "1");
        permissoes.put("Atendente", "2");
        permissoes.put("Pronta Resposta", "3");
    }

Because of some business rules it saves in the bank the values 1, 2 and 3

Okay, he saves on the bench, when I pull the information on a dataTable it is logical that it will pull the information 1, 2 and 3. here is the line of the code that pulls the information in the datatable that’s the one:

<p:column headerText="Permissão de Acesso"
        style="text-align: center">
        <h:outputText value="#{listausuario.permissaoAcesso}" />
</p:column>

as I said, it shows the information I saved, which in case are 1, 2 and 3, now my difficulty is in the xhtml change this data to the names of each example value 1 in the datatable show Supervisor, I saw in some places on the net that I can use Enum, but I don’t really know how it works. Can anyone give me a light? Thank you.

1 answer

1


The best would be to use enum.

As it stands, the solution is this::

1 - Create this method in your class:

public String permissaoAcessoFormatada(){
   switch (permissaoAcesso) {
     case "1":
     return "Supervisor";
     case "2":
     return "Admin";
     case "3":
     return "Mestre";
     default:
     return null;
   }
}

2 - Use the method in your dataTable:

<p:column headerText="Permissão de Acesso"
        style="text-align: center">
        <h:outputText value="#{listausuario.permissaoAcessoFormatada()}" />
</p:column>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.