【问题标题】:Hasmap is not being displayed on selectOneMenu哈希图未显示在 selectOneMenu
【发布时间】:2016-10-02 04:33:37
【问题描述】:

我一直在努力使用由 HashMap 动态填充的 selectOneMenu 一天没有成功,并且找不到发生了什么。 按照上的步骤

How to populate options of h:selectOneMenu from database?

但仍然没有运气

这是我的豆子:

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;
}

这是jsf部分

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

但是当我运行代码时,我只能看到combobx上的“--select--”选项。 有什么我忽略的吗?

提前致谢

【问题讨论】:

    标签: java hashmap selectonemenu


    【解决方案1】:

    试试这个:

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

    来自post的回答和解释

    【讨论】:

    • 是的,我试过了,但还是不行
    • 发现问题。这是beanName。我使用的是 beanAgenda 而不是议程Bean,
    猜你喜欢
    • 2015-11-02
    • 2018-01-16
    • 2023-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-01
    • 1970-01-01
    • 2022-12-10
    相关资源
    最近更新 更多