wood burning stoves*
The moose likes Struts and the fly likes How to capture variables from within iterate tag Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How to capture variables from within iterate tag" Watch "How to capture variables from within iterate tag" New topic
Author

How to capture variables from within iterate tag

Gez Hall
Greenhorn

Joined: Feb 03, 2003
Posts: 1
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

Joined: Dec 19, 2002
Posts: 374
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!


"Write beautiful code; then profile that beautiful code and make little bits of it uglier but faster." --The JavaPerformanceTuning.com team, Newsletter 039.
Arch Tiwari
Greenhorn

Joined: Feb 07, 2003
Posts: 6
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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to capture variables from within iterate tag
 
Similar Threads
return value from main
Priority in Thread
how can i capture a call using a midlet ?
read a .txt file from classpath
server from which page accessed