我正在使用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());
}
}
(此外,请注意,“无效”会使状态及其之前的所有状态无效。如果只想防止该状态,则应使用“丢弃”。https://docs.spring.io/spring-webflow/docs/current/reference/html/views.html#view-backtracking)