使 Spring Webflow 中的上一页快照无效

Invalidate previous page snapshot in Spring Webflow

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

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

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

谢谢

您向哪个州添加了 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