English 中文(简体)
标识错误
原标题:Validation errors in freemarker

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");
    }

}

谁能提供帮助? 奥索尔没有出现错误。

问题回答

页: 1

if(result.hasErrors())
      return redirect(view);

它希望你重新提出新的要求。 你们决不能欺骗,你必须直接放弃这一观点。


查阅my 回答。 这表明何时使用方向,何时可以直接退回。





相关问题
array dependency injection in spring?

is there a way to use dependency injection to inject all available implementations of a specific interface in spring? This is kind of the same thing as asked here for .NET. Though my aim is to use @...

Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Grails Packaging and Naming Conventions

Packaging Controllers, Services,etc. i.e. - com.company.controllers - com.company.services Is this a good practice or should be avoided by all means?? Another worth mentioning problem I encountered ...

How can I determine Objects in application context?

I am trying to write a portlet for Liferay (using Tomcat and Spring) and need to use a database via Persistence API/Hibernate. I am using some configuration XMLs (applicationContext.xml, etc.) and ...

How to prevent JPA from rolling back transaction?

Methods invoked: 1. Struts Action 2. Service class method (annotated by @Transactional) 3. Xfire webservice call Everything including struts (DelegatingActionProxy) and transactions is configured ...

热门标签