aspose file tools*
The moose likes Struts and the fly likes Passing Arraylist from JSP to action class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Passing Arraylist from JSP to action class" Watch "Passing Arraylist from JSP to action class" New topic
Author

Passing Arraylist from JSP to action class

Vijendra Runwal
Ranch Hand

Joined: Apr 17, 2006
Posts: 52
Can anyone help me in finding solution for the following problem :

I have to pass Arraylist from JSP to java action class.I am using strutsframework. I tried setting it using hidden variables but that doesn't work..it gives error for arraylist..

can anyone please give code snippet for the same....

Thanks in Advance..
Vijendra


SCJP 1.4,SCWCD
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
The Commons BeanUtils used by Struts to populate ActionForm beans will not populate an ArrayList automatically. Unless you want to mess around with the inner workings of Struts and the Commons BeanUtils, you really can't pass an ArrayList directly to an ActionForm.

The BeanUtils will populate a String array, however. I'd recommend you change your ActionForm property to type String[]. If your model classes really need an Arraylist, you can always convert the String array to an ArrayList yourself before passing it on to the model.

Here's an example:

In the JSP:

In the ActionForm:



When the form is submitted, myProperty will contain ["foo", "bar", "baz"].


Merrill
Consultant, Sima Solutions
Vijendra Runwal
Ranch Hand

Joined: Apr 17, 2006
Posts: 52
Thanks Merrill..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Passing Arraylist from JSP to action class
 
Similar Threads
Session variable
Collection on jsp
Passing ArrayList
How to display Google chart on JSP
ArrayList and Ajax