0

This is the for each to iterate a list of products and I need to set the productGroupId in the drop down below.

 <c:forEach items="${productgroup.productList}" var="product">

 <h:selectOneMenu  value="${product.appleProdgroupId}">
<f:selectItems value="#{displayProductsBean.productGroupListDropDown}"/>
</h:selectOneMenu>

I have tried all combination but it is not working ...can anyone please help

Sam
  • 295
  • 2
  • 9
  • 24
  • Even when I print the value from the for each using ${product.appleProdgroupId},I get the right value but am unable to select my drop down ...Am actually a newbie to JSF...somebody please help me resolve this.... – Sam Jan 16 '12 at 13:38

1 Answers1

0

It's unclear what exactly you mean with "It is not working". In the code posted so far I see at least 3 possible causes:

Your first problem is that you need to use #{} syntax instead of ${} syntax in order to be able to autocreate managed beans if they do not exist in the scope yet.

<c:forEach items="#{productgroup.productList}" var="product">
    <h:selectOneMenu value="#{product.appleProdgroupId}">
        <f:selectItems value="#{displayProductsBean.productGroupListDropDown}" />
    </h:selectOneMenu>
</c:forEach>

Your second problem is potentially the <c:forEach>, but that depends on the context where this code is running. The <c:forEach> is namely a view build time tag. If the above doesn't work, you'd need <ui:repeat> instead.

<ui:repeat value="#{productgroup.productList}" var="product">
    <h:selectOneMenu value="#{product.appleProdgroupId}">
        <f:selectItems value="#{displayProductsBean.productGroupListDropDown}" />
    </h:selectOneMenu>
</ui:repeat>

If that still doesn't work, then you'd need to attach a <h:messages/> to learn about any missing conversion/validation errors.

<h:messages />

You can for example get a "Value not valid" validation error when the list behind <f:selectItems> is not properly (pre)initialized during the form submit request.

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • I have tried using value="#{product.appleProdgroupId}" but it is not working ..... – Sam Jan 16 '12 at 13:51
  • 1
    Then continue reading the remnant of my answer. On the other hand, you can also try to be more specific in describing the concrete problem instead of saying "it is not working". When you have a flat tire below your car, you also don't say "it is not working" to the car mechanican. – BalusC Jan 16 '12 at 13:53
  • Let me describe the whole design of my problem .In my managed bean I have a list of product group objects.Each product group objects contain a list of product objects.Now I need to display all the products group wise in a data table and provide them a facility to edit inline.Now I am using a for each to iterate my product group list present in the managed bean . – Sam Jan 17 '12 at 04:55
  • So, it's a loop inside a loop? You can't use `` as inner loop of a loop which is to be generated by a JSF component like ``. Use `` or another ``, or for example `` instead. Long story short: read the "See also" link to get a better understanding of how JSTL tags work. – BalusC Jan 17 '12 at 04:56
  • yes a loop inside loop indeed.But when I use ${product.appleProdgroupId}..i get the desired value but am, unable to set it to the value tag of select menu – Sam Jan 17 '12 at 04:59
  • Yes, I know. That's exactly why I have posted an answer how to fix that :) Again, get rid of ``. It does not do what you think it does. – BalusC Jan 17 '12 at 05:01
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/6776/discussion-between-sam-and-balusc) – Sam Jan 17 '12 at 05:42
  • Now when I started to use XHTML instead of jsp my problem got solved.Thanks Balusc for the help – Sam Jan 18 '12 at 08:32