【问题标题】:Spring webflow: Continue to 'next' state from decision-stateSpring webflow:从决策状态继续“下一个”状态
【发布时间】:2014-02-22 05:53:53
【问题描述】:

我的场景是这样的:我需要实现一种在多个流程中进行的授权检查。现在我的一个流程看起来像这样:

<flow parent="myparent-flow">
    <decision-state id="checkAuthorization">
        <if test="bean.notAuthorized" 
            then="redirectToSomePage"
            else="view1" />
    </decision-state>
    <view-state id="view1" />
    <!-- ... -->
</flow>

我需要对多个流程实施相同的授权检查,虽然我可以在任何我真正想要的地方复制粘贴相同的逻辑,但如果可能的话,将它放在已经用于的父流程本身中在每个流程开始时执行一些逻辑。

这里的问题是决策状态下的 else 类。由于它是许多子流的父流,因此它不会知道子流中第一个状态的名称。我想这样使用它,它会以某种方式继续执行流中的下一个状态,该状态存在于子流中。我的最佳解决方案是这样的:

<flow> <!-- flow name = myparent-flow -->
    <decision-state id="checkAuthorization">
        <if test="bean.notAuthorized"
            then="redirectToSomeFlow"
            else="continueExecutionInChildFlow" />
    </decision-state>
    <end-state id="redirectToSomeFlow" view="flowRedirect:someFlow" />
</flow>

这将被定义为我所有流中的父流,这样我就不必重复这个逻辑。 Spring可以做这样的事情吗?

【问题讨论】:

  • Spring Security 不是检查授权的选项吗?
  • 这实际上并不是严格意义上的授权,更多的是根据 bean 值将用户引导到另一个门户。

标签: spring spring-webflow


【解决方案1】:

实现它的一种可能方法是在特定流上设置一个变量,然后将此变量用于最终状态重定向,例如:

<if test="bean.notAuthorized" 
    then="redirectToSomeFlow" 
    else="${conversationScope.resultView}" />

变量可以通过以下方式设置:

<set name="conversationScope.resultView" value="'viewName'" />

【讨论】:

    猜你喜欢
    • 2012-08-13
    • 1970-01-01
    • 2021-03-19
    • 1970-01-01
    • 2017-11-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-14
    相关资源
    最近更新 更多