File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

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 :
request.setAttribute("products", newProductsList);
Junilu Lacar

Joined: Feb 26, 2001
Posts: 6529

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

Joined: May 11, 2003
Posts: 29
Assuming your ActionClass contains...
//startForm.setProducts(newProductsList); // not required
request.setAttribute("products", newProductsList);
Your JSP page can be populated by using...
<logic:iterate id="product" name="products" type="java.lang.String" >
<bean:write name="product" />
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(
thanks for ur help...


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.
I agree. Here's the link:
subject: How to Populate ArrayList
jQuery in Action, 3rd edition