在流中访问多个请求参数

Access multiple request params in flow

我在 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>

但是,只有第一个 requestParameters 值被设置(即如果 timestamp 是第一个,那么只有它被设置。如果 origin 是第一个,那么只有它被设置) .当我访问第二个和第三个值时,它们的值为 null 而不是传递给它的值。以下是表单提交时传递的表单数据示例:

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

提交表单时所有信息都被传递,但实际上只有第一个 <set> 标签在设置数据。我收到的请求有误吗?有什么我需要在我没有做的地方注册的吗

这就是 <action-state> 的工作方式。仅评估第一个表达式。

如果你想对所有三个进行评估,你可以使用 <on-entry> 来评估其他 2:

    <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>

来自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.

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.

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.