如何预填充重复的 h:selectOneMenu?
将每个订单一个点的工作表单修改为每个订单多个点我在预填充 h:selectOneMenu 时遇到了问题。例外是 java.lang.IllegalArgumentException:值绑定 UISelectItems 的“#{spot.deliveryTypes}”与组件路径 {Component-Path : [Class: javax.faces.component.UIViewRoot,ViewId: /order.jsp] [类:javax.faces.component.html.HtmlForm,Id:pf] [类:javax.faces.component.html.HtmlSelectOneMenu,Id:_idJsp11][类:javax.faces.component.UISelectItems,Id:_idJsp12]}不引用类型为 SelectItem、SelectItem[]、Collection 或 Map 的对象,但类型为: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
以及getter和setter。 列表
已从托管 bean 类 Order 移至类 Spot。
如何访问spot.deliveryTypes?将 # 更改为 $ 没有帮助,因为 value= 不接受 EL。
MyFaces 1.1.8
谢谢。
Modifying working form with one spot per order to multiple spots per order I met problems with prepopulating h:selectOneMenu. Exception is 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
old working JSP code:
<h:selectOneMenu value="#{order.deliveryType}" immediate="true">
<f:selectItems value="#{order.deliveryTypes}" />
</h:selectOneMenu>
new not working JSP code:
<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>
New field was introduced List<Spot> spots
as well as getter and setter. List<SelectItem> getDeliveryTypes()
has been moved from managed bean class Order to class Spot.
How to access to spot.deliveryTypes? Changing # to $ didn't help because value= doesn't accept EL.
MyFaces 1.1.8
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
JSTL 和 JSF 并不能很好地结合在一起。 JSP 不会像您期望的编码那样从上到下进行处理。更确切地说,JSTL先从上到下处理JSP,然后将生成的结果交给JSF自己从上到下处理。这尤其使得
c:forEach
无法满足此类要求。在这种特殊情况下,当轮到 JSF 处理 JSP 页面时,${spot}
将不再存在。您想要使用 JSF
UIData
基于组件而不是c:forEach
。c:forEach
的一个完整的 JSF 替代方案是 战斧的t:dataList
。使用它,您的问题将得到解决。如果您使用的是 Facelets 而不是 JSP,您也可以使用其
ui:repeat
。JSTL and JSF doesn't go nicely hand in hand. The JSP won't be processed from top to bottom as you'd expect from the coding. It's more so that JSTL processes the JSP from top to bottom first and then hands the generated result over to JSF for its own processing from top to bottom. This makes especially the
c:forEach
unusable for this kind of requirements. In this particular case, the${spot}
won't be there anymore when it's JSF's turn to process the JSP page.You'd like to use a JSF
UIData
based component instead ofc:forEach
. A fullworthy JSF alternative to thec:forEach
is Tomahawk'st:dataList
. Use it and your problem will be solved.If it happens that you're using Facelets instead of JSP, you can also use its
ui:repeat
instead.