今天在使用<spring:bind>标签绑定表单中的输入域时,出现了javax.servlet.ServletException: Neither Errors instance nor plain target object for bean name 'loginCommand' available as request attribute异常
调试了很久,也痛苦了很久,最后在一个老外的FAQ上找到了解决思路。:)
使用绑定的目的是在一个查询页面中,将查询条件绑定在
列出java的Controller中的主要方法:
[color=red]
需添加: Map view = errors.getModel();[/color]
JSP代码:
Spring配置:
调试了很久,也痛苦了很久,最后在一个老外的FAQ上找到了解决思路。:)
使用绑定的目的是在一个查询页面中,将查询条件绑定在
列出java的Controller中的主要方法:
protected ModelAndView submit(HttpServletRequest request,
HttpServletResponse response, Object command, BindException errors)
throws Exception {
// 设置过滤条件
ExtendingSqlTemplateDO extendingSqlTemplateDO = (ExtendingSqlTemplateDO) command;
ExtendingSqlTemplateDOExample example = createExampleForFilter(extendingSqlTemplateDO);
// 排序字段
String orderByClause = "id asc";
PageBox pageBox = (PageBox) extendingSqlTemplateDAO.selectByExampleWithPaging(
example, pageSize, curpage, orderByClause);
Map view = new HashMap();
view.put("dataList", pageBox);
return new ModelAndView(pageView, view);
}
[color=red]
需添加: Map view = errors.getModel();[/color]
JSP代码:
<th>模版描述</th>
<td>
<spring:bind path="template.templateDesc">
<input type="text" name="<c:out value='${status.expression}' />" value="<c:out value='${status.value}' />" />
</spring:bind>
</td>
Spring配置:
<bean id="extendingSqlTemplateListController" class="xxx.xxx.xxx.extending.ExtendingSqlTemplateListController" autowire="byName">
<property name="pageView" value="extendingSqlTemplateList" />
<property name="commandName" value="template" />
<property name="commandClass" value="xxx.xxx.xxx.db.dataobject.ExtendingSqlTemplateDO" />
</bean>