【问题标题】:How to prepopulate repeating h:selectOneMenu?如何预先填充重复的 h:selectOneMenu?
【发布时间】:2010-06-23 18:25:39
【问题描述】:

将每个订单一个位置的工作表单修改为每个订单多个位置我在预填充 h:selectOneMenu 时遇到了问题。例外是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&lt;Spot&gt; spots 以及getter 和setter。 List&lt;SelectItem&gt; getDeliveryTypes() 已从托管 bean 类 Order 移至 Spot 类。

如何访问 spot.deliveryTypes?将 # 更改为 $ 没有帮助,因为 value= 不接受 EL。

MyFaces 1.1.8

谢谢。

【问题讨论】:

    标签: java jsf jstl myfaces


    【解决方案1】:

    JSTL 和 JSF 不能很好地结合在一起。 JSP 不会像您对编码所期望的那样从上到下进行处理。更多的是JSTL先从上到下处理JSP,然后把生成的结果交给JSF自己从上到下处理。这使得c:forEach 尤其无法满足此类要求。在这种特殊情况下,当轮到 JSF 处理 JSP 页面时,${spot} 将不再存在。

    您想使用基于 JSF UIData 的组件而不是 c:forEachc:forEach 的完全值得的 JSF 替代品是 Tomahawk's t:dataList。使用它,你的问题就会迎刃而解。

    如果碰巧您使用的是 Facelets 而不是 JSP,您也可以使用它的 ui:repeat 来代替。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多