Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to capture variables from within iterate tag

 
Gez Hall
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi. Can someone please advise how I can capture a variable from within an iteration?
I can output a value by using <bean:write property="prop" value="val"> etc, but how can I assign this value to, say, a String and use it in standard java?
This is really bugging me, hope someone can help
 
David Hibbs
Ranch Hand
Posts: 374
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Gez Hall:
Hi. Can someone please advise how I can capture a variable from within an iteration?
I can output a value by using <bean:write property="prop" value="val"> etc, but how can I assign this value to, say, a String and use it in standard java?
This is really bugging me, hope someone can help

The iterate tag allows you to specify an id parameter for where to store the current item in the iteration. This variable name is used in the pageContext. So to get it, you can use pageContext.getAttribute("idString"). However, this returns Object, so you'll have to keep casting in mind--don't mix your object types too much!
 
Arch Tiwari
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by David Hibbs:

The iterate tag allows you to specify an id parameter for where to store the current item in the iteration. This variable name is used in the pageContext. So to get it, you can use pageContext.getAttribute("idString"). However, this returns Object, so you'll have to keep casting in mind--don't mix your object types too much!


Hi,
Using pageContext.getAttribute("idString") I am only able to retrieve the Iterator index value. How do I assign the value being retrieved in the current <bean:write name="emp" value="ename"> . Say I wish to assign ename to a variable.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic