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

问题描述 投票:1回答:1

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

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

因此,为了禁用后退按钮并仅允许用户使用页面内提供的导航控件,我可以在我的Webflow状态中添加什么?

谢谢

java spring-webflow
1个回答
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());
    }
}

(此外,请注意,“无效”会使状态及其之前的所有状态无效。如果只想阻止该状态,则应使用“丢弃”。https://docs.spring.io/spring-webflow/docs/current/reference/html/views.html#view-backtracking

© www.soinside.com 2019 - 2024. All rights reserved.