【问题标题】:How to pass parameters to spring webflow?如何将参数传递给spring webflow?
【发布时间】:2011-04-15 02:13:24
【问题描述】:

首先,我不知道如何为spring webflow配置restful url请求, 例如,输入地址时如何调用我的 webflow: http://localhost/app/order/edit/1002

很容易写spring mvc控制器来处理这个,但是在webflow的情况下,我不知道如何传递参数。

有人可以帮助我吗? 谢谢

【问题讨论】:

    标签: spring-webflow


    【解决方案1】:

    RequestPathFlowExecutorArgumentHandler 是您要找的吗?

    流程执行器参数处理程序 从请求中提取参数 路径并在 URL 路径中公开它们。

    这允许 REST 样式的 URL 以一般格式启动流程: http://${主机}/${上下文 路径}/${调度程序路径}/${flowId}

    <bean id="flowController" class="org.springframework.webflow.executor.mvc.FlowController">
        <property name="flowExecutor" ref="flowExecutor" />
        <property name="argumentHandler">
            <bean class="org.springframework.webflow.executor.support.RequestPathFlowExecutorArgumentHandler" />
        </property>
    </bean>
    

    【讨论】:

    • 谢谢,JoseK。我认为这就是我想要的,但仍然想知道如何使用 url 之类的:localhost/app/order/edit/1002 来启动到 eidt 订单 1002 的流程?能否请您提供一些示例代码?
    • 顺便说一句,我使用的是spring webflow 2.1.1,我没有找到org.springframework.webflow.executor.mvc.FlowController类和org.springframework.webflow.executor.support类。 spring-webflow-2.1.1.RELEASE.jar中的RequestPathFlowExecutorArgumentHandler
    • 您的链接基于 1.0.x,不是我的版本。
    【解决方案2】:

    尝试读取请求参数,如下所示。 它处理“http://example.com/message?messageId=3”,但在呈现视图时,URL 会更改为“http://example.com/message?execution=e1s1”之类的内容。

    流程代码:

    <?xml version="1.0" encoding="UTF-8"?>
        <flow xmlns="http://www.springframework.org/schema/webflow"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.springframework.org/schema/webflow
            http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd">
    
        <on-start>
            <evaluate expression="FooWebFlowController.create(flowRequestContext)"
                      result="flowScope.fooModel"/>
        </on-start>
    
        <view-state id="view" model="fooModel" view="fooView">
        </view-state>
    </flow>
    

    FooWebFlowController bean:

    import org.springframework.webflow.execution.RequestContext;
    
    @Component
    public class FooWebFlowController {
    
        @Autowired
        private FooDAO fooDAO;
    
        public Foo create(RequestContext requestContext) {
            String messageId = requestContext.getRequestParameters().get("messageId")
            Foo foo = fooDAO.findByMessagId(messageId);
            return foo;
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2014-07-23
      • 2023-03-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-04
      • 2020-03-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多