aspose file tools*
The moose likes Struts and the fly likes Pass a arraylist from Action to JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Pass a arraylist from Action to JSP" Watch "Pass a arraylist from Action to JSP" New topic
Author

Pass a arraylist from Action to JSP

Sudha Joish
Greenhorn

Joined: Nov 07, 2003
Posts: 12
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
sandy gupta
Ranch Hand

Joined: Jan 30, 2001
Posts: 228
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


Adios
Sudha Joish
Greenhorn

Joined: Nov 07, 2003
Posts: 12
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

Joined: Jan 30, 2001
Posts: 228
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

Joined: Nov 07, 2003
Posts: 12
Thanks a ton. That worked!
-- $uDhA
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Pass a arraylist from Action to JSP
 
Similar Threads
Bacis doubt input property in struts-config.xml
NullPointerException in PropertyUtils .getSimpleProperty()
Struts and Popup
How to get a new instance of a form bean?
Path for Tile Does Not Start With a "/" Character