Announcement Announcement Module
Collapse
No announcement yet.
Multiple flows in a portlet Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Multiple flows in a portlet

    Hello everyone,

    I'm writing to ask for help as I'm trying to create a portlet that can run different flows during its execution, by using the "handler mapping" (class PortletModeParameterHandlerMapping) mechanism.

    I''m using Spring 3.0.4.RELEASE, Web Flow 2.2.0, and Liferay as the portlet container.

    I've set up the XML configuration files as described in the Web Flow and Spring Portlet documentation (see the relevant sections at the end of this post), implemented 2 different FlowHandlers (each returning a different flow id), and wrote a simple jsp page with 2 anchor links which would switch the flow in the portlet.

    It doesn't work: even if I click the link and the new URL shown in the browser has the handler mapping parameter set to the correct key, the view rendered remains the same (and in the debugger I can see the the FlowHandler for the desired key is not invoked - that is, the flow has remained the original, default one).

    Note that the WebFlow part is working ok: from the default flow I can easily trigger a subflow call and switch to one of the other flow I defined. It's just that I'd like to have different flows instead of having one single flow which calls the other ones as subflow (I feel it cleaner).

    I paste the relevant part of the files, can anyone tell me where I'm wrong or if what I'm trying to do is not supported?
    Sorry if the question is stupid and the answer is obvious, but it's my first time at Spring, WebFlow and Portlets...

    Many thanks to who's willing to help.

    Regards,
    Gabriele

    Configs:

    Code:
    	<webflow:flow-executor id="flowExecutor">	
    		<webflow:flow-execution-attributes>
    	        <!-- execution redirects don't apply in a Portlet environment -->
    	        <webflow:always-redirect-on-pause value="false"/>
    	    </webflow:flow-execution-attributes>	    
    	</webflow:flow-executor>
    	
    	<webflow:flow-registry id="flowRegistry"
    		flow-builder-services="flowBuilderServices" base-path="/WEB-INF/flows">
    		<webflow:flow-location-pattern value="/**/*-flow.xml" />
    		<webflow:flow-location id="base" path="base-flow.xml"></webflow:flow-location>
    	</webflow:flow-registry>
    
    	<webflow:flow-builder-services id="flowBuilderServices" 
    		view-factory-creator="mvcViewFactoryCreator" />
    		
    	<bean id="mvcViewFactoryCreator"
    		class="org.springframework.webflow.mvc.builder.MvcViewFactoryCreator">
    	</bean>

    Code:
    	<bean id="flussoFlowHandler" 
        	class="it.insiel.sktrdomande.web.flows.FlussoFlowHandler"/>
        	
        <bean id="ricercaFlowHandler" 
        	class="it.insiel.sktrdomande.web.flows.RicercaFlowHandler"/>
    	
    
    	<bean id="parameterMappingInterceptor" class="org.springframework.web.portlet.handler.ParameterMappingInterceptor">
    		<property name="parameterName" value="menuChoice"></property>
    	</bean>
    	
    	<bean id="portletModeParameterHandlerMapping" class="org.springframework.web.portlet.handler.PortletModeParameterHandlerMapping" >
    		<property name="defaultHandler" value="homeFlowHandler"></property>
    		<property name="parameterName" value="menuChoice"></property>
    		<property name="portletModeParameterMap">
    			<map>
    				<entry key="view">
    					<map>
    						<entry key="search" value-ref="searchFlowHandler"></entry>
    						<entry key="home" value-ref="homeFlowHandler"></entry>
    					</map>
    				</entry>
    			</map>
    		</property>
    		<property name="interceptors">
    			<list>
    				<ref bean="parameterMappingInterceptor"/>
    			</list>
    		</property>
    	
    	</bean>
    	
    	<bean id="flowHandlerAdapter" class="org.springframework.webflow.mvc.portlet.FlowHandlerAdapter">
    		<property name="flowExecutor" ref="flowExecutor"></property>
    	</bean>
    JSP Code:

    Code:
    <a href='<portlet:renderURL><portlet:param name="menuChoice" value="search"/></portlet:renderURL>'>Search</a>
    
    <a href='<portlet:renderURL><portlet:param name="menuChoice" value="home"/></portlet:renderURL>'>Home</a>
    FlowHandlers:

    Code:
    package it.insiel.sktrdomande.web.flows;
    
    import org.springframework.webflow.mvc.portlet.AbstractFlowHandler;
    
    public class HomeFlowHandler extends AbstractFlowHandler {
    
    	@Override
    	public String getFlowId() {
    		return "home";
    	}
    
    }
    Code:
    package it.insiel.sktrdomande.web.flows;
    
    import org.springframework.webflow.mvc.portlet.AbstractFlowHandler;
    
    public class SearchFlowHandler extends AbstractFlowHandler {
    
    	@Override
    	public String getFlowId() {
    		return "search";
    	}
    
    }

  • #2
    Hi!

    I have the same problem, do you find a solution?

    Thanks,

    Comment


    • #3
      Hello!

      Unfortunately, no. I dropped that approach and reworked everything as a single flow calling all the other flows in the portlet as subflows.

      I guess no one answering means no one ever tried to do what I described in the first post?

      Regards,
      Gabriele

      Comment


      • #4
        Hi,
        I believe i have same problem and kinda solved it, but i'm afraid it's not appropriate solution - unfortunately my knowledge of portlets is quite limited yet. Basically it comes down to flowExecutionKey which i don't know how to get rid of to start new flow

        Best regards, Eugene.

        Comment


        • #5
          Indeed the documentation suggests "One way to start a new flow is to create a URL targeting the mode without the execution key".

          I tried by simply adding a new "execution key" parameter with an empty value to the URL in the anchor, but this causes webflow to crash with a NullPointerException (I guess the code expects either no execution key parameter or one with a value -- maybe Webflow's authors might consider handling an empty execution key parameter as a missing execution key parameter?).

          Otherwise one could build the link's URL by copying the result of renderURL without the execution key parameter.

          Your solution is interesting, though in the end I'd prefer not to fiddle with webflow's code.

          Comment


          • #6
            Originally posted by gdelprete View Post
            Otherwise one could build the link's URL by copying the result of renderURL without the execution key parameter.
            Do you know how to do this? Sounds like what we need. There are lot of references to portlet:renderURL jsp tag in discussions, but i didn't try it cause i use facaletes and it's available for jsp only.

            Comment


            • #7
              I guess one should use java.util.URL or one URL-builder-like class, and just copy the method, host, port, ecc... and all the parameters except that one which ends with "_execution", from the result URL of portlet:renderURL, to a new URL to use as the href of an anchor.

              eg. (in a JSP page, with an hypothetical URLBuilder class)
              Code:
              <!-- get the current renderURL --> 
              <portlet:renderURL var="myUrl">
                  <portlet:param name="action" value="goToSearchFlow"/>
                  <portlet:param name="myparam1" value="bar"/>
                  ....
              </portlet:renderURL>
              
              <%
                 String url = (String) pageContext.getAttribute("myUrl");
                 URL sourceUrl = new URL(url);
              
                 URLBuilder urlbuilder = new URLBuilder();
                 urlbuilder.setHost(url.getHost());
                 ...
                 ... (copy everything including parameters, except parameter ending in "execution")
                 ...
              
                 URL newUrl = urlbuilder.build();
              
              %>
              
              <a href="<%= newUrl%>">Switch flow</a>
              ... something like this...

              If you try and succeed, please let me know (as I said, I switched to the single-flow approach).

              Comment


              • #8
                Spring webflow + portal - How do you get url parameters in the flow definition?

                Hi,

                I felt this post is related to what I am trying to do and hence the reply here. I am trying to get the url parameters when the user hits the portlet. The flows in the portlet are backed by spring webflow where "requestParameters.flow" for example doesnt give me any results because the requestParameter map is empty. Here is my post - http://forum.springsource.org/showth...261#post337261 . You guys seem to be working with a similar setup of swf in portals. Any ideas or help would be REALLY appreciated..

                --rick

                Comment


                • #9
                  I am not familiar with url parameters. If you can put the parameters in a form, then you can get them from the attributes of currentEvent.

                  Restart a flow is very similar to start a new flow. You submit the flowId with the flowExecutionKey. SWF will resume from the paused state.

                  Comment

                  Working...
                  X