本文介绍了Spring Webflow 2和可收藏的URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前,由于Post/Redirect/Get模式,所有流URL都类似于<site_url>/flow_name?execution=?,并且输入的GET参数未保留.因此,用户无法复制该网址或将其添加为书签.

Currently due to the Post/Redirect/Get pattern all flow urls are something like <site_url>/flow_name?execution=? and input GET parameters are not preserved. Thus the users can't copy the url, or bookmark it.

任何建议如何做到这一点?

Any suggestions how could this be done neatly ?

推荐答案

我们可以通过自定义SWF API的 FlowHandlerAdapter ,为基于SWF的应用程序的URL添加书签.

We can bookmark a SWF based application's URL by customising FlowHandlerAdapter of SWF API.

以下是示例:

我的SWF配置文件应具有:

My SWF configuration file would have:

<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将具有:

My CustomFlowHandlerAdapter would have:

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);
            }
....

这里Iam捕获了NoSuchFlowExecutionException,并重定向到不带任何参数的确切流URL.在这里,您可以捕获并重新包含您的参数

Here Iam catching NoSuchFlowExecutionException and am redirecting to the exact flow URL without any parameters. Here you can capture and re-include your parameters

因此,我可以从任何状态为我的URL添加书签(总是从头开始),如果需要,我也可以发送自己的参数.

Thus I am able to bookmark my URL from any state(always flow starts from first) also I will be able to send my own parameters if required.

这篇关于Spring Webflow 2和可收藏的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 19:55