• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Passing Arraylist from JSP to action class

 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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"].
 
Vijendra Runwal
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Merrill..
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic