This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

using <html:iterate> to display an array in the array

 
david arnold
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

The jsp file get an array groupA from session which has the structure like this:



I want to display the elements of groupB[] in a table, in stead of using jsp script, I am wondering if I can use <html:iterate> to accomplish this?

Thanks for the help!
 
Ankit Garg
Sheriff
Posts: 9528
32
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you need to post your code properly. The code that you gave won't compile as groupB is not declared when it is used in groupA. Also you can't fit a String[] into a String[]. You need to have a 2-d String array. Are you trying to say that you want to iterate over a 2 dimensional array like this



If yes, then I think you can easily do this in Struts 2 (I don't know about struts 1 and you have also not mentioned which version of struts you are using)...
 
david arnold
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Ankit Garg. sorry i did not explain clearly, i am using struts 1.2.9. I have a ActionForm like the following:



In JSP file, there is dropdown list which contains all group names and shows the first one. Now I want to add a table to display the student names in a group when user select a group
from a dropdown list. And user may move students to other table, then I need update the table in form and forward to Action. Could I use Struts <html:iterate> to do this? I know how to use <html:iterate> to display like uid, name, but do not know how to display students array.

For example, if I have 3 group A,B,C, how could I diplay student names in group B using html:iterate ?

Thanks.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's <logic:iterate>, not <html:iterate>. I'm not sure what the confusion is--the iterate tag docs describe it pretty well.

That said, using JSTL may be a better solution--it's recommended that when JSTL and Struts tag functionality overlap that JSTL is used. The Struts tags were written before JSTL existed.
 
Lei Guoguo
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you can use jstl tag, you can write like under code



if not

<%page.setAttribute("groupB", ((Object[])request.getAttribute("groupA"))[3]) %>
<logic:iterator />
 
david arnold
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you David and Lei!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic