我有简单的spring mvc web应用程序。我想将列表绑定到drop down。在这种情况下,列表项通常绑定到下拉列表中;但如果我选择项目并单击提交按钮,它总是传递“0”而不是值。
public EditEmployeeController() {
setCommandClass(Employee.class);
setCommandName("employee");
}
@Override
protected Map referenceData(HttpServletRequest request) throws Exception {
Map referenceData = new HashMap();
List roleList = roleService.listRoles();
referenceData.put("roleList", roleList);
return referenceData;
}
@Override
protected ModelAndView onSubmit(HttpServletRequest request,
HttpServletResponse response,
Object command,
BindException errors) throws Exception {
Employee employee = (Employee) command;
employeeService.updateEmployee(employee);
return new ModelAndView(getSuccessView());
}
这是我的观点(jsp)
<c:nestedPath path="employee">
<form method="post" action="./EditEmployee.htm">
........
.......
Select Role :
<c:bind path="roleID">
<select name="roleLists">
<s:forEach items="${roleList}" var="role" >
<option value="<s:out value="${role.roleID}"/>" <s:if test="${role.roleID == status.value}"> selected="selected"</s:if>><s:out value="${role.title}"/></option>
</s:forEach>
</select>
</c:bind>
<input type="submit" value="Update employee"/
</form>
</c:nestedPath>
任何想法解决我的问题.. ??
提前感谢!
答案 0 :(得分:3)
使用Spring表单标记
在jsp中添加<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
并使用下面的代码
<form:select path="role" id="role" >
<form:options items="${roleList}" itemValue="roleID" itemLabel="title"/>
</form:select>