简体   繁体   English

访问流中的多个请求参数

[英]Access multiple request params in flow

I have an action state in a Spring Web Flow that take in parameters from a submitted form:我在 Spring Web Flow 中有一个动作状态,它从提交的表单中获取参数:

<action-state id="newToken">
    <set name="requestScope.timestamp" value="requestParameters.timestamp" type="java.lang.String"/>
    <set name="requestScope.origin" value="requestParameters.origin" type="java.lang.String"/>
    <set name="requestScope.tokenHmacToValidate" value="requestParameters.tokenHmacToValidate" type="java.lang.String"/>
    <transition to="validateToken"/>
</action-state>

However, only the first requestParameters value gets set (ie if timestamp is first, then only it gets set. If origin is first, then only it gets set).然而,只有第一个requestParameters值被设置(即如果timestamp是第一个,那么只有它被设置。如果origin是第一个,那么只有它被设置)。 When I access the second and third values, they have a value of null instead of the value that is passed into it.当我访问第二个和第三个值时,它们的值为null而不是传递给它的值。 Here is an example of form data that is passed on form submission:以下是表单提交时传递的表单数据示例:

_eventId=tokenValidationEvent
origin=https%3A%2F%2Flocalhost%3A8443
timestamp=20200218171041
tokenHmacToValidate=**REDACTED**

All the information is getting passed when the form is submitted, but only the first <set> tag is actually setting data.提交表单时所有信息都会传递,但只有第一个<set>标签实际上是设置数据。 Am I receiveing the request wrong?我收到的请求有误吗? Is there something I need to register somewhere that I'm not doing有什么我需要在我没有做的地方注册的吗

This is the way <action-state> works.这就是<action-state>工作方式。 Only the first expression is evaluated.仅计算第一个表达式。

If you want all three to be evaluated, you could use <on-entry> to evaluate the other 2:如果您希望对所有三个进行评估,您可以使用<on-entry>来评估其他两个:

    <action-state id="newToken">
        <on-entry>
            <set name="requestScope.timestamp" value="requestParameters.timestamp" type="java.lang.String"/>
            <set name="requestScope.origin" value="requestParameters.origin" type="java.lang.String"/>
        </on-entry>
        <set name="requestScope.tokenHmacToValidate" value="requestParameters.tokenHmacToValidate" type="java.lang.String"/>
        <transition to="validateToken"/>
    </action-state>

From https://docs.spring.io/spring-webflow/docs/current/reference/html/actions.html#action-state来自https://docs.spring.io/spring-webflow/docs/current/reference/html/actions.html#action-state

After the execution of each action, the action-state checks the result to see if matches a declared transition to another state.执行每个动作后,动作状态检查结果以查看是否与声明的转换到另一个状态相匹配。 That means if more than one action is configured they are executed in an ordered chain until one returns a result event that matches a state transition out of the action-state while the rest are ignored.这意味着如果配置了多个动作,它们将在有序链中执行,直到返回一个与动作状态之外的状态转换相匹配的结果事件,而其余的则被忽略。 This is a form of the Chain of Responsibility (CoR) pattern.这是责任链 (CoR) 模式的一种形式。

The result of an action's execution is typically the criteria for a transition out of this state.操作执行的结果通常是退出此状态的标准。 Additional information in the current RequestContext may also be tested as part of custom transitional criteria allowing for sophisticated transition expressions that reason on contextual state.当前 RequestContext 中的附加信息也可以作为自定义转换标准的一部分进行测试,允许基于上下文状态的复杂转换表达式。

Note also that an action-state just like any other state can have one more on-entry actions that are executed as a list from start to end.还要注意,动作状态就像任何其他状态一样,可以有一个更多的入口动作,这些动作从头到尾作为列表执行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM