File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Object Relational Mapping and the fly likes Spring 3 drop down Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Spring 3 drop down" Watch "Spring 3 drop down" New topic

Spring 3 drop down

Baskar Sikkayan
Ranch Hand

Joined: Oct 06, 2011
Posts: 30
I am using spring3 MVC and annotation based controller.
In my jsp i have a drop down box as shown below.

<form:select path="experienceInYears">
<formptions items="${experienceYearsMap}" />

I have a property for the drop down in the form class.

public class SeekRegForm {

private int experienceInYears;

private Map<String,String> experienceYearsMap;

* @return the experienceInYears
public int getExperienceInYears() {
return experienceInYears;

* @param experienceInYears
* the experienceInYears to set
public void setExperienceInYears(int experienceInYears) {
this.experienceInYears = experienceInYears;

* @return the experienceYearsMap
public Map<String, String> getExperienceYearsMap() {
return experienceYearsMap;

* @param experienceYearsMap the experienceYearsMap to set
public void setExperienceYearsMap(Map<String, String> experienceYearsMap) {
this.experienceYearsMap = experienceYearsMap;


Here, is my controller.

public class SeekRegController {

@Resource(name = "experienceInYearsMap")
private Map<Integer, Integer> experienceInYearsMap;

@RequestMapping(method = RequestMethod.GET)
public String showForm(Map model, HttpServletRequest request) {
SeekRegForm seekerForm = new SeekRegForm();
model.put("experienceYearsMap", experienceInYearsMap);
model.put("seekRegForm", seekerForm);
return "seekregform"; // This will take to seekregform.jsp

@RequestMapping(method = RequestMethod.POST)
public String registerSeeker(@Valid SeekRegForm seekRegForm,
BindingResult result, Map model) {

if (result.hasErrors()) {
return "seekregform"; // If there is any validation error, it will again go to the same page.


Here, my problem is, if there is any validation error the same form gets loaded with previously filled values.
But drop down is not getting loaded. Do i need to again set drop down values as below inside if(result.hasErrors()) block before forwarding.

model.put("experienceYearsMap", experienceInYearsMap);

I agree. Here's the link:
subject: Spring 3 drop down
jQuery in Action, 3rd edition