views:

15

answers:

1

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.

+1  A: 

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 of c:forEach. A fullworthy JSF alternative to the c:forEach is Tomahawk's t: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.

BalusC