Arshad Ali
Arshad Ali

Reputation: 3274

why List<String> is always returning size 1 in this case

I want to send selected options of a select to controller using following

<form action="/save" method="POST" >             
         <input type="text" name="name"/>
         <label>Subjects</label>
         <select name="subjects">
            <option value="English">English</option>
            <option value="Maths">Maths</option>
         </select>

     <input type="submit" value="Save">
</form>

In controller while form is posted I check the size of subjects list

@RequestMapping(params={"subjects"}, value = "/save-std", method = RequestMethod.POST)
    public String saveStd(@ModelAttribute("std")Student std,
            @RequestParam("subjects") List<String> subjects) {
        System.out.println("List Size is " + subjects.size() );         
        return "home";
    }

it always shows List Size is 1 in the console, why it happens or any better solution to get all selected options?

Upvotes: 0

Views: 111

Answers (1)

CrazyJavaLearner
CrazyJavaLearner

Reputation: 368

Please refer to this link. This may help you.

"Request parameters are a Multimap of String to String. You cannot pass a complex object as request param."

Upvotes: 1

Related Questions