Announcement Announcement Module
Collapse
No announcement yet.
Controller to Web Flow? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Controller to Web Flow?

    Hi All,

    I'm new to spring flows.
    Right now I'm using a controller to load my model and view (an xhtml page).
    When this page posts I'd like to make use of Spring Web Flows.

    How can I do this? Right now a post back does not seem to trigger my controller.

  • #2
    Hello

    I'm new to spring flows.
    Welcome, I suggest you read the SWF documentation

    Right now I'm using a controller to load my model and view (an xhtml page).
    OK, I assume is Spring MVC about @Controller, right?

    When this page posts I'd like to make use of Spring Web Flows.
    Until my knowledge you cant use a Spring MVC controller for SWF, you could create your own Action class that has the same equivalent role than a Controller in Spring MVC

    SWF has many scopes like Flow, Flash View etc, Spring MVC has none knowledge about how work with this

    How can I do this? Right now a post back does not seem to trigger my controller
    If you could post your code would be better to get a complete idea

    Comment


    • #3
      Thanks for the response. Here is some code to give you a better idea of where I stand (I've replaces some logic with comments to shorten it for this purpose)
      And Yes I am using a Spring MVC Controller

      The Controller
      Code:
      public class MyController implements Controller {
      
      	// Some private members	here..	
          	
      	@Override
      	public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse reponse) throws Exception {
      		
      		String strURL;
      		// Some Setup here to figure out URL and some other stuff
      		
      		ModelAndView modelAndView = new ModelAndView(new InternalResourceView(strURL));
      		// Add some objects to te modelAndView...
      		// modelAndView.addObject("someBean", someBean);
      							
      		return modelAndView;
      	}
      	
      	// Some Properties...
      }
      The Web Flow
      Code:
      <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>
      		<!-- Some Startup -->
      	</on-start>
      	
      	
      	<!-- Some <action-state> tags here -->
      		
      	<!-- I want to end up here after post on the view loaded by my controller.... -->
      	<view-state id="getName" view="/WEB-INF/authz/${domainContext.getBranding()}/getName.xhtml" model = "getNameBean">
      		<!-- Some on-render stuff -->
      		<!-- some possible transitions (these would ultimately go to other view-states depending on user input -->
      	</view-state>
      	
      	<!-- I'd eventually end up here -->
      	<end-state id="someEndState" view="theEnd.xhtml" />	
      </flow>
      web-mvcconfig.xml
      Code:
      	<!-- Maps request URIs to controllers -->			
      	<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
      		<property name="mappings">
      			<value>
      				/forgotPassword.htm=myController
      				<!-- There are a bunch of these which use different controllers -->
      				<!-- I also have a flowController (as defined below) which I use for the Spring flows -->
      				/SomePageFlow.htm=flowController
      				/SomeOtherFlow.htm=flowController
      			</value>
      		</property>
      		<property name="defaultHandler">			
      			<bean class="org.springframework.web.servlet.mvc.UrlFilenameViewController" />
      		</property>
      	</bean>
      	
      	<bean id="myController" class="com.mypackage.controller.MyController">
      		<!-- Set Some properties -->
      	</bean>
      	
      	<!-- Handles requests mapped to the Spring Web Flow system -->
      	<bean id="flowController" class="org.springframework.webflow.mvc.servlet.FlowController">

      As I'm typing this post out what I'm thinking I actually need to do is after a post on view loaded by MyController... simply redirect to another url which is mapped to the flow I want to go to...
      Does that make sense?

      The problem I'm having though is that on post back my controller is not executing again so I can handle it this way...

      Please advise if you see something wrong or if the code I have submitted is not sufficient.

      Comment


      • #4
        Please advise if you see something wrong or if the code I have submitted is not sufficient.
        Spring Web Flow cant access a Spring MVC Controller

        You need create an Action class or you could access a POJO from your flow definition, read Spring Web Flow documentation about this 6.5. Action implementations

        Comment


        • #5
          Originally posted by dr_pompeii View Post
          Spring Web Flow cant access a Spring MVC Controller

          You need create an Action class or you could access a POJO from your flow definition, read Spring Web Flow documentation about this 6.5. Action implementations
          I'm not sure you understand the question.
          I want to first use a controller then forward to Spring Flows, not Flow to Controller.

          A change to my above code will be that MyController will extend SimpleFormController
          Right now my pages are all XHTML not JSP so I'll need to modify them to be JSP's in order to use the Spring Form tag to bind to the controller properly.
          On submission of the form I'll perform the necessary validation and redirect to a new URL which will be the spring flows. On part I'll still need to figure out is how I can pass data from the Controller to the flows.

          Make Sense?

          Comment


          • #6
            Hello

            I want to first use a controller then forward to Spring Flows, not Flow to Controller.
            OK, you could consider use

            Code:
            return "redirect:yourflowurl";
            A change to my above code will be that MyController will extend SimpleFormController
            It could be has sense only if you after to insert your form object (POST submit) you want start inmediatley a flow process

            Right now my pages are all XHTML not JSP so I'll need to modify them to be JSP's in order to use the Spring Form tag to bind to the controller properly.
            You can use Spring form tabs within a JSP file, just use the correct namespace

            On submission of the form I'll perform the necessary validation and redirect to a new URL which will be the spring flows. On part I'll still need to figure out is how I can pass data from the Controller to the flows.
            Oh OK, something like this

            Code:
            return "redirect:yourflowurl?someparameter='abc'";
            Your flow definition should request firstly these request parameters, in SWF exists documentation about this

            Comment


            • #7
              Hi! I see how friendly you are guys I'm also new here I guess i should read the SWF documentation too.
              Well, i think i'll bee seeing you more , nice to meet you all

              Comment


              • #8
                While not necessarily directly related to what you want to do, I believe that org.springframework.webflow.mvc.servlet.FlowContro ller is of some relevance here:
                The adapter between the Spring MVC Controller layer and the Spring Web Flow engine. This controller allows Spring Web Flow to run embedded as a Controller within a DispatcherServlet, the key piece of the Spring Web MVC platform. It is expected a DispatcherServlet HandlerMapping will care for mapping all requests for flows to this controller for handling.
                Also this note from org.springframework.webflow.execution: Interface Action clarifies the situation a bit:
                an Action is not a controller like a Spring MVC controller or a Struts action is a controller. Flow actions are commands. Such commands do not select views, they execute arbitrary behavioral logic and then return an logical execution result. The flow that invokes an Action is responsible for responding to the execution result to decide what to do next. In Spring Web Flow, the flow is the controller.
                Last edited by MiB; Jan 12th, 2012, 06:16 AM. Reason: additional info

                Comment

                Working...
                X