Win a copy of Practice Tests for OCP Java 17 Certification Exam (1Z0-829) this week in the OCPJP forum!
  • 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

Need to pass Javascript Array to Struts 2 Action

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need to pass a Javascript Array full of data to my Struts 2 action. I'm currently doing this on submit by assigning the Array to a hidden field:

I have this sending through the value to a String array, but it appears in my action as a single element in the array with comma delimited values. My questions are:
Is there a better way to do this?
Is there a way to get an actual array passed through to my action?

Thanks,
Fletcher
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
AFAIK there's no magic that will automatically convert a CSV string into an array.

There's no way to pass "an array": the ONLY thing that browsers send back to servers are strings. You could write a converter that makes it into an array (and donate it to the S2 project), but you'd have to specify the type in code or configs, so it might not be a general-purpose thing.

Another option is to create multiple hidden fields with the same name; S2 will gather those and set them on a collection property (maybe array too, but I don't know that for sure). If order is significant you'd need to name them appropriately, using array syntax notation for the field names.
 
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic