【问题标题】:Spring webflow global transitions, determine the "validate" attribute dynamicallySpring webflow 全局转换,动态确定“验证”属性
【发布时间】:2014-09-05 18:44:02
【问题描述】:

我声明了一个全局转换,我希望将“验证”属性的值设置为条件或设置为动作状态。 这是我想做的事情:

<decision-state id="decision_view">
    <if test="condition == true" then="actionState1" />
</decision-state>

<action-state id="actionState1">
    <evaluate result="flowScope.validateGT1" expression="true"/>
</action-state>

<global-transitions>
    <transition on="gtransition1" to="gtransition1" 
    validate="flowScope.validateGT1" /> // Does not work, syntax error
</global-transitions>

这种语法根本不起作用。有没有办法动态确定验证布尔值? 我正在做的项目是使用 2.3.1 版本的 Spring webflow。

谢谢。

【问题讨论】:

  • 你试过validate="${flowScope.validateGT1}"
  • 我的 IDE 显示以下错误:属性值错误。
  • 在执行时:'${flowScope.validateGT1}' n'est pas une valeur valide pour 'boolean'。 (=> 不是有效的布尔值)。

标签: spring jakarta-ee spring-webflow spring-webflow-2


【解决方案1】:

尝试使用evaluate

<evaluate expression="flowScope.validateGT1" result="flag" />

<global-transitions>
    <transition on="gtransition1" to="gtransition1" 
    validate="flag" />
</global-transitions>

【讨论】:

  • 我不确定你的答案是否理解,我认为标签 不能在州外声明。
【解决方案2】:

我认为你不能使用布尔表达式,因为它只需要文字 true 或 false: http://www.w3.org/TR/xmlschema-2/#boolean

检查spring webflow xsd中“验证”的属性类型:

    xsd:attribute name="validate" type="xsd:boolean"

相反,您可以做的是在验证器本身中检索布尔值并决定是否应该进行验证:

    public class YourValidator {
        public void validateStateId(YourModel model, ValidationContext context) {
            RequestContext requestContext = RequestContextHolder.getRequestContext();
            boolean shouldValidate = (Boolean)requestContext.getFlowScope.get("validateGT1");
            if(shouldValidate){
                MessageContext messages = context.getMessageContext();
                ...
            }
        }
    }

【讨论】:

    猜你喜欢
    • 2012-07-31
    • 2013-05-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多