p: selectOneMenu not listed

2

I am in the fight trying to populate a selectOneMenu with data of a Enum , but when I gave up and put the static data with f:selectItem I realized that even then the field is empty.

Even with the value filled with #{clienteBean.teste} the result is the same, where test is an attribute of type String with its getters and setters.

                <p:selectOneMenu id="console" value="" style="width:125px">
        <f:selectItem itemLabel="Select One" itemValue="" />
        <f:selectItem itemLabel="Xbox One" itemValue="Xbox One" />
        <f:selectItem itemLabel="PS4" itemValue="PS4" />
        <f:selectItem itemLabel="Wii U" itemValue="Wii U" />
    </p:selectOneMenu>  

obs: The above example is the same as showcase.

    
asked by anonymous 21.09.2015 / 18:56

1 answer

3

Here's an example:

No Enum:

public enum ClienteTipos{

    SUSPECT("Suspect"),
    PROSPECT("Prospect"),
    CLIENTE("Cliente");

    ClienteTipos(String nome){
        this.nome = nome;
    }

    //Attributes
    private String nome;


    //Properties
    public String getNome(){
       return nome;
    }
}

No ManagedBean:

public SelectItem[] getTiposCliente() {
    SelectItem[] items = new SelectItem[ClienteTipos.values().length];
    int i = 0;
    for(ClienteTipos t: ClienteTipos.values()) {
        items[i++] = new SelectItem(t, t.getNome());
    }
    return items;
}

On the xhtml (JSF) page:

<h:selectOneListbox id="tipo" size="1" value="#{clienteMB.cliente.tipo}">
    <f:selectItems value="#{clienteMB.tiposCliente}" var="t" 
        itemLabel="#{t.nome}" itemValue="#{t}"/>
</h:selectOneListbox>

Source: Enum JSF SelectOneMenu

    
21.09.2015 / 20:31