Two Laptop Bag*
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 The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Spring 3 drop down" Watch "Spring 3 drop down" New topic
Author

Spring 3 drop down

Baskar Sikkayan
Greenhorn

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

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


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

@Repository("seekRegForm")
public class SeekRegForm {

@NotEmpty
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.

@Controller
@RequestMapping("/seekregform.form")
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);


Thanks,
Baskar.S
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Spring 3 drop down