0
我的views.There製作的Spring MVC應用程序和使用Velocity模板的形式是由數據並以這種形式,我使用#springFormSingleSelect.Form填充它正常工作時的數據是有效的,但是當形式由無效數據填充提到有與錯誤的消息,但#springFormSingleSelect是empty.That的我的觀點:無效的工作
<form action="saveEmployee" method="POST">
#springBind("newEmployee")
<a href="listEmployees">#springMessage("label.back")</a>
<p>
<table>
<tr>
<td>#springMessage("label.firstName")</td>
<td>#springFormInput("newEmployee.firstName" "")</td>
<td><font color="red">#springShowErrors(" " "")</font></td>
</tr>
<tr>
<td>#springMessage("label.lastName")</td>
<td>#springFormInput("newEmployee.lastName" "")</td>
<td><font color="red">#springShowErrors(" " "")</font></td>
</tr>
<tr>
<td>#springMessage("label.salary")</td>
<td>#springFormInput("newEmployee.salary" "")</td>
<td><font color="red">#springShowErrors(" " "")</font></td>
</tr>
<tr>
<td>#springMessage("label.birthdate")</td>
<td>#springFormInput("newEmployee.birthday" "")</td>
<td><font color="red">#springShowErrors(" " "")</font></td>
</tr>
<tr>
<td>#springMessage("label.departament")</td>
<td>#springFormSingleSelect("newEmployee.departamentId" $departamentsMap "")</td>
</tr>
</table>
<input type="submit" value="#springMessage("label.submit")">
</form>
這是控制器到視圖的一部分:
@RequestMapping(value="/saveEmployee", method= RequestMethod.GET)
public ModelAndView newuserForm(){
ModelAndView model = new ModelAndView("newEmployee");
Employee empl = new Employee();
Map departamentsMap = new TreeMap();
List<Departament> departamentsList = service.listDepartaments();
//for singleselect of departaments
for(int i=0; i<departamentsList.size(); i++){
Departament dep = departamentsList.get(i);
departamentsMap.put(dep.getDepartamentId(),dep.getTitle());
}
model.addObject("departamentsMap",departamentsMap);
model.getModelMap().put("newEmployee", empl);
return model;
}
@RequestMapping(value="/saveEmployee", method=RequestMethod.POST)
public String create(@ModelAttribute("newEmployee")Employee empl, BindingResult result){
employeeValidator.validate(empl, result);
if(result.hasErrors()){
return "newEmployee";
}
service.saveEmployee(empl);
return "redirect:/listEmployees";
}
也許有人知道這個原因行爲?