The below code is for single value selection which is working absolutely fine. But when I add attribue multiple="true" to form:select tag, then country object parameter in save() method is having null value when I select multiple value in Jsp. What will be the change that I have to do in jsp so that I can get the list of country objects in controller method. Please advise.
JSP Code
<form:form modelAttribute="country">
<li>
<form:label cssClass="mandatory" path="state">Select State</form:label>
<form:select path="state" cssErrorClass="error">
<form:option value="" label="Please Select..." />
<!-- Collection<State> listOfStates; This value holds the list of State objects by using controller method.-->
<c:forEach items="${listOfStates}" var="s">
<form:option value="${s.stateUniqueCode}" label="${s.stateName}"/>
</c:forEach>
</form:select>
</li>
</form>
Controller method
@RequestMapping(params = "_save", method = RequestMethod.POST)
public ModelAndView save(@ModelAttribute("country") Country country, BindingResult result, SessionStatus status) {
//some busines logic....
return new ModelAndView(mavString.toString());
}
Country and state classes _________________________
/** Country object**/
public class Country{
private State state;
//getter and setters
}
/** State object**/
public class State{
private long stateUniqueCode;
private String stateName;
//getter and setters
}
If I convert country variable to List country in Country class. How should be the jsp and controller method be changed.