Spring Web Flow-页面上有多个表单-验证正确的表单 [英] Spring Web Flow - Multiple forms on page - validating correct form

查看:96
本文介绍了Spring Web Flow-页面上有多个表单-验证正确的表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Spring Web Flow 2.3,并且我有一个页面,上面有两种形式,可以根据提交的形式转换到不同的位置.为此,我为视图状态提供了一个复合模型对象,该对象将两种形式保存在内部.我看到的问题是,如果触发了转换A,则我只想验证表单A,并且同样要使用窗体B-仅当触发了B转换时才想验证B.我不确定如何指出要验证的表格.查看正在验证每个过渡的整个CompositeForm的状态:

I am using Spring Web Flow 2.3 and I have a page that has two forms on it that transition to different places depending on which is submitted. To accomplish this, I have one composite model object for my view-state that holds the two forms inside. The problem I am seeing is that if transition A is fired, I only want to validate form A, and likewise with form B - only want to validate B if B transition fired. I am not sure how to indicate which form to validate. View state that is validating the entire compositeForm for each transition:

<view-state model="compositeForm">
    <transition on="formAsubmit" to="formApage" validate="true"/>
    <transition on="formBsubmit" to="formBpage" validate="true"/>
</view-state>

有人知道我如何触发自定义验证器以根据触发的转换进行不同的验证?

Does anyone know how I can trigger a custom validator to validate differently depending on which transition was fired?

感谢您的帮助.

史蒂夫

推荐答案

我最终要做的是在提交表单B时手动触发我的验证,然后过渡到检查是否存在验证错误的决策状态.这有点丑陋,但我觉得这是最好的方法:

What I ended up doing was to manually trigger my validation when form B was submitted and transition to a decision-state that checks if there were validation errors. It's a little ugly, but I feel like it's the best way:

<view-state id="start" model="compositeForm">
    <transition on="formAsubmit" to="pageA" validate="true"/>
    <transition on="formBsubmit" to="isFormBValid" validate="false">
        <evaluate expression="formBValidator.validate(compositeForm.formB, messageContext)"/>
    </transition
</view-state>

<decision-state id="isFormBValid">
    <if test="messageContext.hasErrorMessages()" then="start" else="pageB"/>
</decision-state>

这篇关于Spring Web Flow-页面上有多个表单-验证正确的表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆