Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

How to Populate ArrayList

 
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 15815
264
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This tutorial has good examples of how to use Lists in conjuction with html:select and html:options
[ September 12, 2003: Message edited by: Junilu Lacar ]
 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 325
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
manasa teja
Ranch Hand
Posts: 325
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 325
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am stii getting the same error. I put teh bean in request, session..
still it is throwing me teh same error.
 
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic