目前由于Post/Redirect/Get模式,所有流量URL类似于<site_url>/flow_name?execution=?
,并且输入GET参数未保留。因此,用户不能复制网址或将其加入书签。Spring Webflow 2和可加书签的URL
任何建议怎么会这样整齐呢?
目前由于Post/Redirect/Get模式,所有流量URL类似于<site_url>/flow_name?execution=?
,并且输入GET参数未保留。因此,用户不能复制网址或将其加入书签。Spring Webflow 2和可加书签的URL
任何建议怎么会这样整齐呢?
你总是可以使用和书签链接到你的流量的起点之一。
比如,你可以做<site_url>/flow_name?personId=123&projectId=456
假设你有两个输入您的流量personId
和projectId
。但你需要知道网址(你将不得不把它交给用户),你不能使用地址栏上的那个。
即使你想这样做,你也不能使用书签链接到你的流程中的一个特定状态(除非你在流程开始时添加一些逻辑来指导你到一个特定的事件取决于输入的值)。
我们可以通过自定义SWF API的FlowHandlerAdapter来为基于SWF的应用程序的URL添加书签。
这里有一个例子:
我的SWF的配置文件将有:
<bean id="flowController" class="org.springframework.webflow.mvc.servlet.FlowController">
<property name="flowHandlerAdapter" ref="customFlowHandlerAdapter" />
</bean>
<bean id="customFlowHandlerAdapter" class="com.xyz.CustomFlowHandlerAdapter">
<property name="flowExecutor" ref="flowExecutor" />
<property name="flowUrlHandler" >
<bean class="com.xyz.CustomURLFlowHandler" />
</property>
</bean>
我CustomFlowHandlerAdapter将有:
public class CustomFlowHandlerAdapter extends FlowHandlerAdapter {
...
@Override
public ModelAndView handle(HttpServletRequest request,
HttpServletResponse response, Object handler) throws Exception {
FlowHandler flowHandler = (FlowHandler) handler;
checkAndPrepare(request, response, false);
String flowExecutionKey = this.getFlowUrlHandler()
.getFlowExecutionKey(request);
if (flowExecutionKey != null)
try {
ServletExternalContext context = createServletExternalContext(
request, response);
FlowExecutionResult result = this.getFlowExecutor().resumeExecution(
flowExecutionKey, context);
handleFlowExecutionResult(result, context, request, response,
flowHandler);
} catch(org.springframework.webflow.execution.repository.NoSuchFlowExecutionException ex){
response.sendRedirect(request.getRequestURI());
} catch(org.springframework.webflow.execution.repository.BadlyFormattedFlowExecutionKeyException ex){
response.sendRedirect(request.getRequestURI());
} catch (FlowException e) {
handleFlowException(e, request, response, flowHandler);
}
....
这里荫醒目NoSuchFlowExecutionException和我重定向到确切的流没有任何参数的网址。在这里,您可以捕获并重新包含您的参数
因此,我能够从任何状态为书签我的URL(始终从第一个流程开始),如果需要,我也能够发送自己的参数。
我认为用“流”的想法是,单个步骤对书签没有意义。如果他们这样做了,他们应该在流程之外。也就是说,试图将流程作为一个整体加入书签是很不幸的 - 这意味着回到开始的步骤 - 并不干净,因为所有步骤的URL都有一些执行键。 – dbreaux