• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Spring 3 drop down

Baskar Sikkayan
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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);

  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic