aspose file tools*
The moose likes Struts and the fly likes How to Populate ArrayList Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How to Populate ArrayList" Watch "How to Populate ArrayList" New topic
Author

How to Populate ArrayList

sudhakar Tadepalli
Ranch Hand

Joined: Dec 27, 2001
Posts: 130
Hi all,
I have a ArrayList with Strings in request object and trying to populate in Jsp. Could any one give me sample code for it?. I am trying with Iterator,optionsCollection and option collection..etc but no luck.
I am setting the arrayList into request object as well setting to Form bean though we no need to do both, just for testing purpose I am doing this.
If I put Arraylist in request object without setting to FormBean how can we populate and If I set it to Form bean then how to populate?.
Note: My ArrayList have just string names not beans.
My ActionClass code :
newProductsList.add("Test1");
newProductsList.add("Test2");
newProductsList.add("Test3");
startForm.setProducts(newProductsList);
request.setAttribute("products", newProductsList);
Thanks
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4419
    
    5

This tutorial has good examples of how to use Lists in conjuction with html:select and htmlptions
[ September 12, 2003: Message edited by: Junilu Lacar ]

Junilu - [How to Ask Questions] [How to Answer Questions]
Neeraja Neeraj
Greenhorn

Joined: May 11, 2003
Posts: 29
Assuming your ActionClass contains...
newProductsList.add("Test1");
newProductsList.add("Test2");
newProductsList.add("Test3");
//startForm.setProducts(newProductsList); // not required
request.setAttribute("products", newProductsList);
Your JSP page can be populated by using...
<table>
<logic:iterate id="product" name="products" type="java.lang.String" >
<tr>
<td>
<bean:write name="product" />
</td>
</tr>
</logic:iterate>
</table>
Should work now. Pls check it up.
manasa teja
Ranch Hand

Joined: May 27, 2002
Posts: 325
I tried implementing the above example.. but, it is throwing me the following error.. what cld be the reason....
[Servlet Error]-[Cannot find bean product in any scope]: javax.servlet.jsp.JspException: Cannot find bean product in any scope
at org.apache.struts.util.RequestUtils.lookup(RequestUtils.java:714)
thanks for ur help...

regards


MT
manasa teja
Ranch Hand

Joined: May 27, 2002
Posts: 325
Any suggestions , why this is throwing "bean not found " error.
Appreciate ur help
[ October 06, 2003: Message edited by: M K Raman ]
[ October 07, 2003: Message edited by: M K Raman ]
manasa teja
Ranch Hand

Joined: May 27, 2002
Posts: 325
I am stii getting the same error. I put teh bean in request, session..
still it is throwing me teh same error.
 
jQuery in Action, 2nd edition
 
subject: How to Populate ArrayList
 
Similar Threads
Form Elements and Arrays
Pass a arraylist from Action to JSP
Question in struts
Automatic Population of Indexed Fields
enctype="multipart/form-data" request.getParameter() issue