0

I've been strugling with selectOneMenu dinamically populated by a HashMap without success for a day now, and can´t find what´s going on. Followed the steps on

How to populate options of h:selectOneMenu from database?

but still no luck

Here´s my bean:

private Paciente selectedPaciente;
private Map<String, String> itensPacientes; 


@PostConstruct
    public void init() {
        itensPacientes = new LinkedHashMap<String, String>();
        itensPacientes.put("1","teste1");
        itensPacientes.put("2","teste1");
        itensPacientes.put("3","teste1");     
}


public Map<String, String> getItensPacientes() {
        return itensPacientes;
}

public Paciente getSelectedPaciente(){
        return selectedPaciente;
}

public void setSelectedPaciente(Paciente selectedPaciente){
        this.selectedPaciente = selectedPaciente;
}

and here's the jsf portion

    <h:selectOneMenu  value="#{beanAgenda.selectedPaciente}" required="true">   
        <f:selectItem itemValue="#{null}" itemLabel="--select--" />       
        <f:selectItems value="#{beanAgenda.itensPacientes}" 
           itemValue="#{entry.key}" itemLabel="#{entry.value}"/>
    </h:selectOneMenu>

But when I run the code, I can only see the "--select--" option on the combobx. Is there something I'm overlooking?

Thanks in advance

Community
  • 1
  • 1

1 Answers1

0

Try this:

<f:selectItems value="#{beanAgenda.itensPacientes.entrySet()}" var="entry" 
       itemValue="#{entry.key}" itemLabel="#{entry.value}"/>

Answer and explanation from this post

Community
  • 1
  • 1
Manu AG
  • 188
  • 1
  • 6