File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to capture variables from within iterate tag