• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Iterating a Array in Struts2

 
Vamshi Jampala
Ranch Hand
Posts: 40
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Filename: temp2deltenames.bmp
Description: The Way it should be on the jsp page
File size: 80 Kbytes
[Download temp2deltenames.bmp] Download Attachment
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 40
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 40
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried using var but no luck, it just prints me the var in the text fields.
 
Vamshi Jampala
Ranch Hand
Posts: 40
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
for convenience attached the image as how its displayed on jsp
 
Ankit Garg
Sheriff
Posts: 9497
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you use the var attribute, then it should work
 
Vamshi Jampala
Ranch Hand
Posts: 40
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"%{}" 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
Posts: 40
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic