2010-06-23 146 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