我已经为我的JSP表单实现了自定义验证,并且当出现错误时,返回表单并将我的错误绑定到BindingResult。我的形式看起来像:我怎样才能让我的错误(在BindingResult)绑定到我的领域?
<form:form name="createCustomer" action="/practicemvc/customers/create/" method="POST" modelAttribute="customerBean">
<form:errors />
<label for="customerName">Name</label>
<input type="text" name="name" id="customerName" value="${customerBean.name}" />
<form:errors path="name" />
显示在错误:
<form:errors />
但是,他们没有被显示通过:
<form:errors path="name" />
我的错误被合并到BindingResult有:
for(ErrorType errorType: validationResult.getErrors()) {
bindingResult.addError(new ObjectError(errorType.getProperty(),
new String[]{errorType.getErrorCode()}, null, null));
}
getPro perty()将返回“name”,getErrorCode()返回“INVALID_EMAIL”。 “INVALID_EMAIL”通过我的messageSource bean转换为“您的电子邮件无效”。如果我在BindingResult中查看错误的内容,一切似乎都没问题,但它们在我的JSP中没有按预期输出。有任何想法吗?
感谢,B
要小心,让objectName像表单中的commandName一样,并且像className一样。请参阅:http://ansaurus.com/question/1363753-spring-mvc-tag-doesnt-find-error-messages – 2013-03-08 14:31:40
但*字段*没有吸气剂 – gstackoverflow 2017-05-23 09:26:07