Announcement Announcement Module
Collapse
No announcement yet.
@RequestParam unable to retrieve array values Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • @RequestParam unable to retrieve array values

    Hi,
    I am facing a problem in submitting a simple html form , in which an array of values is being submitted to Spring Controller. In that controller I have following method
    @RequestMapping(method = RequestMethod.GET)
    public String setupForm(@RequestParam(value=TIME_IDS, required=false) Long[] time_ids,...)
    but that is showing my array values in form of comma seperated string values
    i.e (3302,3305,3304) instead of an long array.

    Thanks to all.

  • #2
    Based on this thread, You might have to wrap your array as a model attribute.

    Another approach would be to use:

    Code:
    @RequestParam(value=TIME_IDS, required=false) String time_ids
    then call time_ids.split(",") to parse each value. Kind of hacky, but it's a start.

    Comment


    • #3
      I appreciate your reply.How can I wrap an array that is being submitted from a form which is not bound to any model attribute.In my case array is just a request paramter. As far spliting an string to array is over task for the developer. Don't you think when I am giving Long[] type in my argument defintion then spring should convert this for me.

      Comment


      • #4
        > How can I wrap an array that is being submitted from a form which is not bound to any model attribute.In my case array is just a request paramter.

        If you simply declare the method parameter as a String, it will be effectively wrapped as a comma-separated list of values in a String.

        > Don't you think when I am giving Long[] type in my argument defintion then spring should convert this for me.

        I don't know if Spring supports this out of the box, but you can certainly make your own PropertyEditor and register it with an @InitBinder annotated method in your controller. See here for more information on custom type binding.

        Comment


        • #5
          Thanks jamestatic. I will try this as per your reference.

          Comment

          Working...
          X