|
|
Tag lt;spring:hasBindErrors/gt; : always return false
Hello,
I implemented a quot;school casequot; where I have to display a field error (the date is badly entered). Here my code (school case) :
Code:
@ActionMapping(params = quot;command=actionSearchFormInstancequot;)
public void searchFormInstance(
@RequestParam(value = quot;pagequot;, required = true, defaultValue = quot;1quot;) Integer pPage,
@RequestParam(value = quot;isSearchquot;, required = true, defaultValue = quot;truequot;) Boolean pIsSearch,
@ModelAttribute FormInstanceSearchBinder pFormInstanceSearchBinder,
BindingResult bindingResult, ActionResponse response,
SessionStatus sessionStatus) {
formInstanceSearchValidator.validate( pFormInstanceSearchBinder,
bindingResult );
if (!bindingResult.hasErrors())
{
...
}
}
The JSP:Code:
lt;spring:hasBindErrors name=quot;formInstanceSearchBinderquot;gt;
lt;c ut value=quot;allErrors: ${fn:length(errors.allErrors)}quot;gt;lt;/c utgt;
lt;c ut value=quot;${fn:length(status.errorMessages)}quot;gt;lt;/c utgt;
lt;font style=quot;color: #C11B17;quot;gt;lt;c:forEach
items=quot;${status.errorMessages}quot; var=quot;errorquot;gt;
lt;spring:message code=quot;${error.code}quot; text=quot;testequot; /gt;
lt;/c:forEachgt;lt;/fontgt;
lt;/spring:hasBindErrorsgt;
And the validator:Code:
@Component(quot;formInstanceSearchValidatorquot;)
public class FormInstanceSearchValidator implements Validator {
@Override
public boolean supports(Classlt;?gt; klass) {
return FormInstanceSearchBinder.class.isAssignableFrom( klass );
}
@Override
public void validate(Object target, Errors errors) {
FormInstanceSearchBinder item = (FormInstanceSearchBinder) target;
try
{
DateUtil.getAsObject( item.getCreationDate(),
DateUtil.DEFAULT_DATE_PATTERN );
}
catch (ParseException e)
{
errors.rejectValue( quot;creationDatequot;,
quot;typeMismatch.formInstanceSearchBinder.creationDatequot; );
}
//int a = errors.getGlobalErrorCount();
//int b = errors.getFieldErrorCount();
//int c = errors.getErrorCount();
}
}
When I put a break point in the @ActionMapping method, the test Code:
if (!bindingResult.hasErrors())
return false, which means there are errors on this ModelAttribute. So why are they not displayed in the JSP ?
I really don't understand.
I just followed the school case at : sprin...g/BindTag.html
Thanks for your help ! |
|