2

I have a JSTL <c:forEach> loop:

 <c:forEach items="${myBean.itemList}" var="items"/>

The loop creates an <h:selectOneMenu> with <f:selectItem>:

<h:selectOneMenu title="selectMenu">
    <f:selectItem itemLabel="First Item" itemValue="${items.itemID}"/>
</h:selectOneMenu>

I am not able to access the ${items.itemID} in the itemValue tag.

I have tried using both #{} and ${} syntax, and neither are working properly. The value always appears to be null. I know that it is not null as there is another button that passes in the <c:forEach> var and it is not null.

Is there any way I can access that var from the <c:forEach> loop inside of my <f:selectItem>?

Tiny
  • 27,221
  • 105
  • 339
  • 599
Curly5115
  • 103
  • 1
  • 3
  • 13
  • [JSTL in JSF2 Facelets… makes sense?](http://stackoverflow.com/a/3343681/1391249). In a nutshell, make use of `` instead i.e. replace `` by a corresponding ``. (I assumed that you are using a `` inside a ``). – Tiny Mar 24 '15 at 16:15
  • 2
    @Tiny: this code should work just fine, provided that OP is using JSF2+Facelets and `itemID` property is not empty. The for JSF2+Facelets unnecessary usage of `${}` instead of `#{}` is however a vague hint that OP is actually using JSF1+JSP (moreover, no one sane JSF2+Facelets tutorial mentions usage of `${}`). In that case, other rules may apply (note that `` doesn't exist in JSP). OP's question history unfortunately doesn't contain any hints which JSF version OP is actually using. – BalusC Mar 24 '15 at 17:07
  • @BalusC Thanks for you comments gents. I am using JSF 1.2 – Curly5115 Mar 24 '15 at 18:45
  • 1
    As I guessed. However, based on your JSF questions asked so far I don't have the impression that you're working on an existing JSF project and are kind of playing around with JSF (or you're simply really good at asking focused questions ;) ). In case you're indeed hobbying, it should be not that hard to just upgrade to the latest available JSF version, which is currently 2.2. And, make sure that you pay attention to release date and used versions in JSF books/tutorials. JSF2 was introduced end of 2009 already, which is a rather major step forward as compared to JSF 1.x (JSP was deprecated). – BalusC Mar 24 '15 at 18:54
  • Unfortunately, I am using an existing project - I guess I am good at focused questions? Unfortunately, I am not able to upgrade the JSF version. My current thinking is changing the JSTL foreach loop to a JSF DataTable so that my JSF selectOneMenu can have access to the current item in the list. – Curly5115 Mar 25 '15 at 13:57

0 Answers0