将每个订单一个位置的工作表单修改为每个订单多个位置我在预填充 h:selectOneMenu 时遇到了问题。异常(exception)是java.lang.IllegalArgumentException: Value binding '#{spot.deliveryTypes}'of UISelectItems with component-path {Component-Path : [Class: javax.faces.component.UIViewRoot,ViewId: /order.jsp][Class: javax.faces.component.html.HtmlForm,Id: pf][Class: javax.faces.component.html.HtmlSelectOneMenu,Id: _idJsp11][Class: javax.faces.component.UISelectItems,Id: _idJsp12]} does not reference an Object of type SelectItem, SelectItem[], Collection or Map but of type : null
旧的工作 JSP 代码:
<h:selectOneMenu value="#{order.deliveryType}" immediate="true">
<f:selectItems value="#{order.deliveryTypes}" />
</h:selectOneMenu>
新的不工作的 JSP 代码:
<c:forEach var="spot" items="${order.spots}">
<h:selectOneMenu value="#{spot.deliveryType}" immediate="true">
<f:selectItems value="#{spot.deliveryTypes}" /> <%-- Works as empty list if this line removed --%>
</h:selectOneMenu> <c:out value="${spot.name}"/><br/>
</c:forEach>
引入了新字段List<Spot> spots
以及 getter 和 setter。 List<SelectItem> getDeliveryTypes()
已从托管 Bean 类 Order 移至类 Spot。
如何访问spot.deliveryTypes?将 # 更改为 $ 没有帮助,因为 value= 不接受 EL。
MyFaces 1.1.8
谢谢。
最佳答案
JSTL 和 JSF 并不能很好地结合在一起。 JSP 不会像您期望的编码那样从上到下进行处理。更确切地说,JSTL先从上到下处理JSP,然后将生成的结果交给JSF自己从上到下处理。这尤其使得 c:forEach
无法满足此类要求。在这种特殊情况下,当轮到 JSF 处理 JSP 页面时,${spot}
将不再存在。
您想使用 JSF UIData
基于组件而不是 c:forEach
。 c:forEach
的一个完整的 JSF 替代方案是 Tomahawk's t:dataList
。使用它,您的问题将得到解决。
如果您碰巧使用 Facelets 而不是 JSP,您也可以使用它的 ui:repeat
相反。
关于java - 如何预填充重复 h :selectOneMenu?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3104413/