2010-06-23 97 views
1

修改每个订单一个点的工作表单到每个订单多个点我遇到了预填充问题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如何预先填充重复h:selectOneMenu?

旧工作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

谢谢。

回答

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