• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
Bartenders:
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

Pass a arraylist from Action to JSP

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi pple
am a struts-beginner and i need some help on passing an Arraylist frm Action to JSP.
i cud use Session or request.setAttribute ( ) to get this done. but i am sure there is a 'struts-way' of doing this.
in the execute ( ) of SetUpMessageAction, i have:


i have a CategoryBean with int id, String description. in service.getCategories ( ), i do
repeatedly to populate the Arraylist.
from Action, request is fwd-ed to ContactPage.jsp, where I need to get the 'categories' collection to populate my combo box.
this is how i try to populate the combo box:


in my struts-config.xml, this is wht i have:

the exception i get is:


what does that mean? am i not setting 'categories' explicitly in Action? what am i missing here?
i had another question:

What exactly does this do?
thanks a ton.
-- $uDhA
 
Ranch Hand
Posts: 228
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Whatever you are trying to do can be done in a much simpler faishon by using an arraylist in your dynaactionform and passing the list of categories to it and accessing it in the jsp using normal struts tags or jstl tags.
All you will need to do is define a variable of type arraylist in the form bean and then populate that object in the action.
This is the right way to do it too.
Second Q:
mapping.getAttribute()
Returns the request-scope or session-scope attribute name under which your form bean is accessed.
This looks at the actionMapping done in struts-config and gets the scope attribute from there.
HTH
Sahil
 
Sudha Joish
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please see if I have understood you right:
In the Action class:


In struts-config.xml:


In the JSP:



I still get the same error:


What am I missing here ?! Am a week new to Struts, so please tell me where I am going wrong.
Thanks
-- $uDhA
 
sandy gupta
Ranch Hand
Posts: 228
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sudha,
first thing, dun do the request.setAttribute(..., categories) in your action instead control it from your action-mapping where you can define the scope that your bean should reside in.
Second on the jsp page, you need to create a jsp bean from the form bean attribute and then pass that to the html ptions or html ptionsCollection tags or you could use the iterate tag from jstl.
http://www.mail-archive.com/struts-user@jakarta.apache.org/msg84643.html
Check out this post, this is exactly what you should be doing.
Thanks
Sahil
 
Sudha Joish
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a ton. That worked!
-- $uDhA
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic