5

I have a j2ee application developed using spring framework and spring webflow. Currently all of my url requests go through the Web Flow. What I want is to be able to choose whether to direct it to Web Flow or an ordinary spring mvc controller. I have no idea how to direct it to custom controllers. How do I do this?

I tried having this in my web.xml but i can't direct it to the bean controller specified in mytest2-servlet.xml

<servlet>
    <servlet-name>mytest</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet
    </servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value></param-value>
    </init-param>
    <load-on-startup>2</load-on-startup>
</servlet>

<servlet>
    <servlet-name>mytest2</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet
    </servlet-class>
    <init-param>
        <param-name>contextConfigLocation2</param-name>
        <param-value></param-value>
    </init-param>
    <load-on-startup>2</load-on-startup>
</servlet>


<servlet-mapping>
    <servlet-name>mytest</servlet-name>
    <url-pattern>*.do</url-pattern>
</servlet-mapping>

<servlet-mapping>
    <servlet-name>mytest2</servlet-name>
    <url-pattern>*.htm</url-pattern>
</servlet-mapping>

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
        /WEB-INF/web-application-config.xml
</param-value>
</context-param>

<context-param>
    <param-name>contextConfigLocation2</param-name>
    <param-value>
        /WEB-INF/mytest2-servlet.xml
</param-value>
</context-param>
Nathan Hughes
  • 94,330
  • 19
  • 181
  • 276
cedric
  • 3,107
  • 15
  • 54
  • 65
  • I suggest you to refer to [Spring Web Flow: Spring MVC Integration](http://static.springsource.org/spring-webflow/docs/2.0.x/reference/html/ch10.html). – Adeel Ansari Jan 21 '10 at 07:29
  • What is close to what I need is the custom flow handler topic in the link you gave. Is there a way to direct requests not to the Webflow but to another controllers. I added something in my question – cedric Jan 21 '10 at 08:26
  • You can do it with plain Servet Filter, I guess, if there is really no other way in Spring. Actually, not working with Spring presently, and it has been 2+ years when I last time worked on it. – Adeel Ansari Jan 22 '10 at 07:32

3 Answers3

1

Try this in your end state

<end-state id="exit" view="externalRedirect:controllerURL" />

where 'controllerURL' is the URL that your controller listens to/

Alan Robles
  • 31
  • 2
  • 8
1

The simplest way to mix both Web Flows and plain Spring MVC Controllers is to simply register the plain Controllers at URL paths outside any of your flow paths.

For instance, here are some excerpts from our configuration files, loaded from web.xml by the single instance of the DispatchServlet:

<!-- Simple URL-view mapping without controller (or flow) -->
<mvc:view-controller path="/selectLanguage" view-name="selectLanguage"/>

<!-- Maps request paths to flows in the flowRegistry;
     e.g. a path of /hotels/booking looks for a flow with id "hotels/booking". -->
<bean class="org.springframework.webflow.mvc.servlet.FlowHandlerMapping" p:order="-1">
    <property name="flowRegistry" ref="flowRegistry" />
    <property name="interceptors">
        <list>
            <!-- for each flow, if a param lang=xx is added, switch locales -->
            <bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor"
                  p:paramName="lang"/>
        </list>
    </property>
</bean>

<!-- The registry of executable flow definitions -->
<webflow:flow-registry id="flowRegistry" flow-builder-services="flowBuilderServices" base-path="/WEB-INF">
    <!-- Flows created from all -flow.xml files, with the flow ID being the path name -->
    <webflow:flow-location-pattern value="/**/*-flow.xml" />
</webflow:flow-registry>

So WebFlow will register all URL paths that correspond to a WEB-INF/**/something-flow.xml file, and all other URL paths, like /selectLanguage above, can be handled by a regular Controller.

dbreaux
  • 4,982
  • 1
  • 25
  • 64
0

write a dispatcher-sevlet.xml or configuration file, write a separate configuration file ( for convenience ) for Spring Flows just import the files in dispatcher-servlet.xml.

Harish Kadamudi
  • 129
  • 2
  • 9