【问题标题】:Getting multiple drop down list value from view in JSF 2.0从 JSF 2.0 的视图中获取多个下拉列表值
【发布时间】:2012-12-06 05:57:58
【问题描述】:

我正在尝试使用 JSF 根据从视图到控制器的用户输入来检索多个下拉列表。

但是我似乎找不到正确的方法。

由于下拉列表是动态生成的,我无法硬编码下拉列表的 ID/名称。

这是我在视图中的代码:

                    <ui:repeat var="file" value="#{uploadBean.filesInZip}" varStatus="status">
                        <tr>
                            <td><h:outputText value="#{file.name}" /></td>
                            <td>
                                <h:selectOneMenu id="studentSelections" value="#{uploadBean.studentSelections}" name="studentSelections">
                                    <f:selectItems value="#{uploadBean.students}" var="student" 
                                        itemLabel="#{student.firstName}, #{student.lastName} (#{student.userId})" 
                                        itemValue="#{student.id}"/>
                                </h:selectOneMenu>
                            </td>
                        </tr>
                    </ui:repeat>

我以为我可以在控制器中声明一个名为 studentSelections 的列表,以便我可以获得下拉列表的所有用户输入,但似乎我失败了。

那么有人可以帮忙吗?

【问题讨论】:

    标签: java jsf-2


    【解决方案1】:

    我以为我可以在控制器中声明一个名为 studentSelections 的列表,以便我可以获得下拉列表的所有用户输入,但似乎我失败了。

    这是正确的模型方法。在视图方面,您需要按&lt;ui:repeat varStatus&gt; 提供的索引引用列表值。假设 #{student.id}Long 而你有一个

    private List<Long> studentSelections;
    

    那么这应该在你的特定情况下做

    <h:selectOneMenu ... value="#{uploadBean.studentSelections[status.index]}">
    

    与具体问题无关the &lt;h:selectOneMenu&gt; doesn't support the name attribute at all。摆脱它。 JSF 自动生成一个。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-02-24
      • 2012-07-27
      • 1970-01-01
      • 2021-05-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-30
      相关资源
      最近更新 更多