This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to Populate ArrayList

 
sudhakar Tadepalli
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
 
Junilu Lacar
Bartender
Pie
Posts: 7465
50
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • 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 htmlptions
[ September 12, 2003: Message edited by: Junilu Lacar ]
 
Neeraja Neeraj
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.
 
manasa teja
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic