1

I am trying to use JSF to retrieve multiple drop down lists according to user input from the view to controller.

However seems I cannot find the correct way.

As the drop down lists are generated dynamically, I cannot hard code the id / name of the drop down list.

Here is my code in the view:

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

I thought I could declare a List named studentSelections in the controller so that I could get all the user input of the drop down list, but seems I have failed.

So could anyone give a hand on it?

4

1 回答 1

2

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

这是正确的模型方法。在视图方面,您需要按索引引用列表值,如<ui:repeat varStatus>. 假设那#{student.id}Long并且你有一个

private List<Long> studentSelections;

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

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

与具体问题无关<h:selectOneMenu>根本不支持该name属性。摆脱它。JSF 自动生成一个。

于 2012-12-06T13:04:53.353 回答