【问题标题】:Spring WebFlow: view-state is not calling validation method before <evaluate> tagSpring WebFlow:视图状态未在 <evaluate> 标记之前调用验证方法
【发布时间】:2013-11-02 12:39:29
【问题描述】:

这个问题快把我逼疯了。

我有以下视图状态:

 <on-start>
    <evaluate expression="new com.zxxztech.zecure.services.webflow.FormularioConfirmacionCorreo()"
        result="flowScope.ccForm" />
 </on-start>

<view-state id="activacionManual" model="ccForm" >
    <transition on="enviar" to="resultado" bind="true">
        <evaluate expression="usersManager.activarUsuario(ccForm.correo, ccForm.codigo)"
            result="flowScope.resultado" />  
    </transition>
    <transition on="cancelar" to="cancelar" validate="false" bind="false" />
</view-state>

这就是 Validation 类:

@Component
public class FormularioConfirmacionCorreoValidator {


 @Autowired
 private UsersManager usersManager;

 public void validateActivacionManual(FormularioConfirmacionCorreo ccForm, ValidationContext validContext) {
         ...
         [Validation logic]

}

  public UsersManager getUsersManager() {
    return usersManager; 
  }

 public void setUsersManager(UsersManager usersManager) {
       this.usersManager = usersManager;
 }
}

表单提交时,webflow直接执行标签,不调用校验方法。

我不知道我做错了什么。

编辑:

这是 activacionManual.jsp 文件:

              ...
              <form:form cssClass="ym-form" modelAttribute="ccf" method="post" action="${flowExecutionUrl}">
                <form:errors cssClass="ym-error" element="div" path="*"/>
                <div class="ym-box">
                    <div class="ym-fbox">
                        <label for="correo"><spring:message
                                code="activacion.form.correo.label"
                                text="activacion.form.correo.label" /></label> 
                        <form:input path="correo" />
                    </div>
                    <div class="ym-fbox">
                        <label for="codigo"><spring:message
                                code="activacion.form.codigo.label"
                                text="activacion.form.codigo.label" /></label>
                                <form:input path="codigo" />
                    </div>
                    <div class="ym-fbox-footer ym-fbox-button">
                        <input class="ym-button ym-gr" type="submit" 
                            value="<spring:message code="formulario.button.cancelar" text="formulario.button.cancelar" />"
                            name="_eventId_cancelar">
                        <input class="ym-button ym-primary ym-gr" type="submit"
                            value="<spring:message code="formulario.button.enviar" text="formulario.button.enviar" />" 
                            name="_eventId_enviar">
                    </div>
                </div>
              </form:form>
              ...

【问题讨论】:

  • 您没有调用任何验证方法。你认为你到底在哪里称呼它?
  • 我是按照reference manual做的
  • 是的。你触发了哪个转换?
  • 我正在提交带有“_eventId_enviar”按钮的表单。查看编辑。
  • 可能值得尝试在模型中指定验证方法的替代机制。在您的FormularioConfirmacionCorreo 中尝试添加一个方法public void validateActivacionManual(ValidationContext ctxt)。看看这是否被调用。

标签: spring validation spring-webflow


【解决方案1】:

第二种方法是定义一个单独的对象,称为验证器,用于验证您的模型对象。为此,首先创建一个名称具有模式 ${model}Validator 的类,其中 ${model} 是模型表达式的大写形式,例如 booking。然后定义一个名为 validate${state} 的公共方法,其中 ${state} 是您的视图状态的 id,例如 enterBookingDetails。

因此,由于您的model 属性为ccForm,因此验证器类必须命名为CcFormValidator。 (或重命名您的 model 属性。)

(另外,我认为您的 JSP 使用 modelAttribute="ccf" 而不是 "ccForm" 会出现问题。模型名称需要在 flow.xml、JSP 和验证器之间匹配。)

【讨论】:

    猜你喜欢
    • 2011-05-07
    • 1970-01-01
    • 2010-09-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-07
    • 1970-01-01
    • 2011-05-14
    相关资源
    最近更新 更多