It's not a secret anymore!
The moose likes Struts and the fly likes Struts 2 Iterating in ArrayList containing object Array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts 2 Iterating in ArrayList containing object Array" Watch "Struts 2 Iterating in ArrayList containing object Array" New topic

Struts 2 Iterating in ArrayList containing object Array

Divy Prakash

Joined: Feb 02, 2009
Posts: 10

I know that we can iterate through an arrylist using iterator tag in Struts 2 .

But my Array list contains multiple object arrays.

So how can i itreate through those object arrays present inside the ArrayList?

I need to diplsy it on JSP page using Struts 2.

Ankit Garg

Joined: Aug 03, 2008
Posts: 9453

This shouldn't be much of a sweat. You can iterate over the elements in the ArrayList and then iterate over the Object[] in each element. The smallest piece of code that can do this would look like this

SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
nitin jha

Joined: Nov 18, 2009
Posts: 2
I have ArrayList in request which contais bean object I am not able to Itrate this bean in jsp

What is the problem in this code???

ArrayList approverList = activateApproverDAO.getApproverRecord();
System.out.println("got List form PRM Database...");
Iterator itr = approverList.iterator();
while (itr.hasNext()) {
ActivateApproverBeanVO activateApproverBeanVO = (ActivateApproverBeanVO);
System.out.println("User Id....."+ activateApproverBeanVO.getUserId());
System.out.println("Approver Type...."+activateApproverBeanVO.getApproverType());

request.setAttribute("listApprover", approverList);


<logic:iterate id="appId" name="listApprover" scope="request">
<bean:define id="approverRecord" name="appId"
type="com.techm.sdp.prm.vo.ActivateApproverBeanVO" />
<logic:iterate id="approverDetail" name="approverRecord">
<td class="tdspace" align="left">
<bean:write name="approverDetail" property="userId" />
<td class="tdspace" align="left">
<bean:write name="approverDetail" property="approverType" />
<td class="tdspace" align="right">
<bean:write name="approverDetail" property="status" />
Ankit Garg

Joined: Aug 03, 2008
Posts: 9453

Hi Nitin, please start a new topic for your question. Click on to start a new topic. Also please UseCodeTags to wrap your code inside [code][/code] tags...
Nitin Surana
Ranch Hand

Joined: Jan 21, 2011
Posts: 129

Here is a working example (Netbeans 6.9) project, which not only
iterates over a list of custom POJOs/Objects/Beans, but also re-creates the list of objects on form submission, so at the receiving action only the setter of that particular
list is required.
Simply resolve the references and get going.
I agree. Here's the link:
subject: Struts 2 Iterating in ArrayList containing object Array
It's not a secret anymore!