aspose file tools*
The moose likes Struts and the fly likes Iterating a Array in Struts2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Iterating a Array in Struts2" Watch "Iterating a Array in Struts2" New topic
Author

Iterating a Array in Struts2

Vamshi Jampala
Ranch Hand

Joined: Feb 23, 2008
Posts: 40

When i Use value="someStringArray[%{#someStringArrayStatus.index}]"
it prints someStringArray[0],someStringArray[1],someStringArray[2] in the text fields instead of the actual value

when i try value="%{someStringArray[%{#someStringArrayStatus.index}]}"
the page is not at all rendered

I am new to Struts2 n trying to figure the mistake I am doing, any help is greatly appreciated!

Thanks for your time


[Download temp2deltenames.bmp] Download

David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Too many colors, not enough code tags.

Please UseCodeTags when posting code or configuration. Unformatted code and configuration is very difficult to read. You can edit your post to include them by using the button.

If you're just trying to use the current value of iteration as the textfield value, use the "id" (or "var", depending on version) attribute and use that.
Vamshi Jampala
Ranch Hand

Joined: Feb 23, 2008
Posts: 40
Thank you for letting me know about the code tags,
will try var and will let you know
thanks again for your time.
Vamshi Jampala
Ranch Hand

Joined: Feb 23, 2008
Posts: 40
I tried using var but no luck, it just prints me the var in the text fields.
Vamshi Jampala
Ranch Hand

Joined: Feb 23, 2008
Posts: 40
for convenience attached the image as how its displayed on jsp
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9293
    
  17

If you use the var attribute, then it should work


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Vamshi Jampala
Ranch Hand

Joined: Feb 23, 2008
Posts: 40
Hi Ankit,

You were absolutely Right, previously i wasn't using the var properly,



will do the trick
Where can I find the proper explanation on when to use % and # ?

Thanks for your time
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

"%{}" is just the OGNL escape sequence, like ${} is for JSP EL. It's occasionally optional, but most people prefer to use it explicitly to avoid any confusion.

The "#" character is used to refer to named value stack objects; it's also not always required, particularly in S2.1+... but it's also fairly inconsistent; I still use it most of the time to avoid confusion.
Vamshi Jampala
Ranch Hand

Joined: Feb 23, 2008
Posts: 40
Now I have much more clear picture of what is used for what, thankyou guys

http://struts.apache.org/2.0.14/docs/ognl.html
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Iterating a Array in Struts2