I try to write password validator with spring and freemarker. BindingResult see errors, but they not showing - spring.status.errorMessages?size returns 0. Validator get correct passwords, because I checked. PasswordForm is a java class with passwords. I put below fragments.
投入形式:
<tr>
<td><@m.formPassword path= passwordForm.passwordOld label= user.passwordOld classes= attr= /></td>
<td><@m.fieldErr /></td>
</tr>
面积:
"macros.ftl" as m
宏观应用:
<#macro fieldErr>
<#if (spring.status.errorMessages?size > 0)>
<label> blaaad</label>
</#if>
<label> size=${spring.status.errorMessages?size}</label>
</#macro>
<#macro formPassword path label= classes= attr= required=false>
<@spring.bind "${path}" />
<#assign error = />
<#if (spring.status.errorMessages?size > 0)>
<#assign error = err /></#if>
<#if label??>
<br/>
<label class="inputLabel ${error} <#if required>required </#if>"><@spring.message code="${label}" /></label>
</#if>
<@spring.formPasswordInput path="${path}" attributes= class="inputText ${classes} ${error}" AUTOCOMPLETE="off" />
<#if (spring.status.errorMessages?size > 0)>
<span class="err">${spring.status.errorMessage}</span>
</#if>
</#macro>
主计长:
@RequestMapping(method = RequestMethod.POST)
public String onSubmit(
@ModelAttribute("passwordForm") PasswordForm passwordForm,
BindingResult result,
ModelMap model,
SessionStatus sessionStatus,
HttpSession session) {
passwordValidator.validate(passwordForm, result);
if(result.hasErrors())
return redirect(view);
return redirect(View.MAIN);
}
鉴定人:
@Override
public void validate(Object target, Errors errors) {
PasswordForm passwordForm = (PasswordForm) target;
String passwordOld = passwordForm.getPasswordOld();
String passwordNew = passwordForm.getPasswordNew();
String passwordNewRepeat = passwordForm.getPasswordNewRepeat();
if (StringUtils.isBlank(passwordOld)) {
errors.rejectValue("passwordOld", "password.blank");
}
if (!StringUtils.equals(passwordNew, passwordNewRepeat)) {
errors.rejectValue("passwordNewRepeat", "password.notmatch");
errors.rejectValue("passwordNew", "password.notmatch");
}
}
谁能提供帮助? 奥索尔没有出现错误。