aspose file tools*
The moose likes Struts and the fly likes using <html:iterate> to display an array in the array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "using <html:iterate> to display an array in the array" Watch "using <html:iterate> to display an array in the array" New topic
Author

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

david arnold
Ranch Hand

Joined: Apr 10, 2009
Posts: 133
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

Joined: Aug 03, 2008
Posts: 9293
    
  17

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)...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
david arnold
Ranch Hand

Joined: Apr 10, 2009
Posts: 133
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

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Mar 31, 2009
Posts: 26
if you can use jstl tag, you can write like under code



if not

<%page.setAttribute("groupB", ((Object[])request.getAttribute("groupA"))[3]) %>
<logic:iterator />


I'm a chinese, my english is so bad, I need help. If you want to help me, you can send your question to my e-mail: lgg860911@yahoo.com.cn, I will help you, and improve my english. Thanks everyone.
david arnold
Ranch Hand

Joined: Apr 10, 2009
Posts: 133
Thank you David and Lei!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: using <html:iterate> to display an array in the array