aspose file tools*
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
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
Author

Struts 2 Iterating in ArrayList containing object Array

Divy Prakash
Greenhorn

Joined: Feb 02, 2009
Posts: 10
Hi,

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.

Thanks
DP
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9303
    
  17

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
Greenhorn

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)itr.next();
System.out.println("User Id....."+ activateApproverBeanVO.getUserId());
System.out.println("Approver Type...."+activateApproverBeanVO.getApproverType());
System.out.println("Status....."+activateApproverBeanVO.getStatus());
}

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" />
<tr>
<logic:iterate id="approverDetail" name="approverRecord">
<td class="tdspace" align="left">
<bean:write name="approverDetail" property="userId" />
</td>
<td class="tdspace" align="left">
<bean:write name="approverDetail" property="approverType" />
</td>
<td class="tdspace" align="right">
<bean:write name="approverDetail" property="status" />
</td>
</logic:iterate>
</tr>
</logic:iterate>
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9303
    
  17

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.
 
Don't get me started about those stupid light bulbs.
 
subject: Struts 2 Iterating in ArrayList containing object Array