【问题标题】:Invalidate previous page snapshot in Spring Webflow在 Spring Webflow 中使上一页快照无效
【发布时间】:2020-01-18 04:47:11
【问题描述】:

我正在使用 Spring Webflow,我正在从 view-state 重定向到 action-stateview-state。现在,当用户在第二个view-state 时,我不希望用户能够单击浏览器后退按钮并转到上一页。

我发现,history="invalidate" 可以用来使上一页的快照失效。我尝试在transition 中使用它。但是,它不起作用(浏览器后退按钮未禁用)。

那么,为了禁用后退按钮并只允许用户使用页面内提供的导航控件,我可以添加什么到我的 webflow 状态?

谢谢

【问题讨论】:

    标签: java spring-webflow


    【解决方案1】:

    您将history 属性添加到哪个状态?

    首先,<action-state> 不支持它 (https://jira.spring.io/browse/SWF-1481)。

    您必须将其添加到第一个 <view-state> 的转换中。如果您只想根据<action-state> 中发生的事情有条件地这样做,那是不够的。我们最终创建了 Java 代码以从我们的 <action-state> 方法调用来执行此操作。

    /**
     * Invalidate WebFlow history. For use in action-state, where the transition element is not able
     * to specify to invalidate history.
     */
    public static void invalidateHistory() {
        RequestContext context = RequestContextHolder.getRequestContext();
    
        synchronized(context.getFlowExecutionContext()) {
            DefaultFlowExecutionRepository r =
                    (DefaultFlowExecutionRepository)
                    ((FlowExecutorImpl)
                        context.getActiveFlow().
                        getApplicationContext().
                        getBean(FlowExecutor.class)).getExecutionRepository();
            r.removeAllFlowExecutionSnapshots((FlowExecution)context.getFlowExecutionContext());
        }
    }
    

    (另外,请注意,“invalidate”会使状态及其之前的所有状态都无效。如果您只想阻止该单个状态,则可以使用“discard”。https://docs.spring.io/spring-webflow/docs/current/reference/html/views.html#view-backtracking

    【讨论】:

      猜你喜欢
      • 2013-08-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-25
      • 1970-01-01
      • 1970-01-01
      • 2013-08-08
      相关资源
      最近更新 更多