• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • Carey Brown
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • fred rosenberger
  • salvin francis

How to capture variables from within iterate tag

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 374
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic