Announcement Announcement Module
Collapse
No announcement yet.
SWF + Portal get URL parameters Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • SWF + Portal get URL parameters

    Hi,

    I am a newbie to SWF and portal and I have to combine their usage for a project involving login and password recovery related user flows. I am using a single flow as the point of the entry and then branching off to different subflows depending on whether the user enters by accessing the portlet directly or trying to enter a confirmation code (emailed as a link embedded in the url). Problem is that my requestParameter map is empty even when I try to pass any url parameters the first time. I am guessing it has something to do with the ViewFlowHandler but not sure.

    Here is my context config:

    Code:
    <!-- Maps portlet modes to handlers -->	
    	<bean id="portletModeHandlerMapping" class="org.springframework.web.portlet.handler.PortletModeHandlerMapping">
    		<property name="portletModeMap">
    			<map>
    				<entry key="view">
    					<bean class="com.mycompany.login.portlet.ViewFlowHandler" />
    				</entry>
    			</map>
    		</property>
    	</bean>
    	
    	<!-- Enables FlowHandlers -->
    	<bean class="org.springframework.webflow.mvc.portlet.FlowHandlerAdapter">
    		<property name="flowExecutor" ref="flowExecutor"/>
    	</bean>
    	
    	<!-- Executes flows: the central entry point into the Spring Web Flow system -->
    	<webflow:flow-executor id="flowExecutor">
    	</webflow:flow-executor>
    	
    	<!-- The registry of executable flow definitions -->
    	<webflow:flow-registry id="flowRegistry" flow-builder-services="flowBuilderService">
    		<webflow:flow-location path="classpath:flows/login-flow.xml" />
    		<webflow:flow-location path="classpath:flows/main-flow.xml" />
    		<webflow:flow-location path="classpath:flows/pwd-recovery-flow.xml" />
    	</webflow:flow-registry>
    	
    	<webflow:flow-builder-services id="flowBuilderService" view-factory-creator="viewFactoryCreator"/>
    	
    	<bean id="viewFactoryCreator" class="org.springframework.webflow.mvc.builder.MvcViewFactoryCreator">  
    		<property name="viewResolvers">  
    			<list>  
    				<ref bean="viewResolver"/>  
    			</list>  
    		</property>  
    	</bean>  
    	
    	<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    		<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
    		<property name="prefix" value="/WEB-INF/flow-views/"/>
    		<property name="suffix" value=".jsp"/>
    	</bean>
    Here is my simple ViewFlowHandler which always returns the name of my single point of entry flow

    Code:
    package com.mycompany.login.portlet;
    
    import javax.servlet.http.HttpServletRequest;
    
    import org.springframework.webflow.core.collection.LocalAttributeMap;
    import org.springframework.webflow.core.collection.MutableAttributeMap;
    import org.springframework.webflow.mvc.portlet.AbstractFlowHandler;
    
    
    public class ViewFlowHandler extends AbstractFlowHandler{
    	public String getFlowId() {
            return "main-flow";
        }
    	
    }

    And here is part of my single point of entry flow which redirect to other flows based on a url parameter I cannot get . I have tried all permutations - action state starts with on-entry evals, on-entry evals but my requestParameters is always empty.

    Code:
    	<action-state id="proceed">
    	
    		<evaluate expression="flowNames.setNflow(requestParameters.flo)"/>
      		
     		<evaluate expression="flowNames.nflow"/>
    		<transition on="pwd-recovery" to="pwd-recovery"/>
    		<transition on="finish" to="finish-main"/>
    		<transition to="login"/>
    		
    	</action-state>

    And my url (emailed link):
    http://localhost:8080/portal/portal/...o=pwd-recovery

    I am trying to pass "flo" parameter and restart the flow for that user. And none of that is happening

    My Questions:

    1. How do I get url parameters from url in swf + portlet setup like this?
    2. How do I instruct webflow to restart the flow when this emailed link is clicked? (not specifying an executionkey didnt work )

    Thanks a lot in advance for taking the time to read this long question. Any help is appreciated a lot!
    Last edited by rickster911; Jan 3rd, 2011, 01:18 PM.

  • #2
    help.. anyone?

    Sorry.. just curious if anyone can help? Im essentially trying to do 2 things

    1. get url parameters in the flow in a portlet env (requestParameter map is empty right now)

    2. restart a flow - how do i do this?

    im a newbie to swf + portals so these might be stupid questions but I've looked around n couldnt find answers relevant to swf + portlet env.. any help would be great

    Comment


    • #3
      1. pass the externalContext to the method,

      PortletRequest request = (PortletRequest)externalContext.getNativeRequest() ;
      (HttpServletRequest)request.getAttribute("javax.se rvlet.request");
      You can extract the parameter from the HttpRequest.

      2. Call the end state when emailed link clicked. The end state will restart the flow.

      Comment


      • #4
        Re: Got the URL without the get parameters

        Thanks for your reply. I did try this and managed to get the httpservletrequest. The requestparameter is empty . Also used this code to get the outermost request

        Code:
        PortletRequest request = (PortletRequest)externalContext.getNativeRequest() ;
        		HttpServletRequest rawRequest = null;
                PortletInvocation invocation = (PortletInvocation)request.getAttribute("org.jboss.portal.attribute.component_invocation");
                if (invocation != null) {
                    rawRequest = (HttpServletRequest) invocation.getDispatchedRequest();
                }
                HttpServletRequest outerRequest = rawRequest;
                while(outerRequest instanceof HttpServletRequestWrapper) 
                {
                    outerRequest = (HttpServletRequest)((HttpServletRequestWrapper)outerRequest).getRequest();
                }
        
        String url = outerRequest.getRequestURL();
        //This returned the URL only till the name of the portlet. Not the parameters.
        // URL Used: http://localhost:8080/portal/portal/default/Login/SD+LoginWindow?_flowId=main-flow&flo=pwd-recovery
        How do I get those url parameters? Sorry I tried looking for other ways but couldnt find any.

        Comment


        • #5
          Look like parameter is not passed!

          Install HttpWatch in Firefox and check it whether all the parameter is passed.

          Comment


          • #6
            Got it!!

            Sweet.. got it.. will document here for someone else stuck with this problem

            Basically I had to iterate and get to the outermost request as shown in the code below after passing the "externalContext" from the evaluate expression in the state. So

            1. In the flow called this on entry

            Code:
            	<on-start>
            		<evaluate expression="flowNames.setNextFlow(externalContext)"/>
            	</on-start>
            2. And the method definition for setNextFlow is given below

            Code:
            	public Flows setNextFlow(ExternalContext externalContext){
            		PortletRequest request = (PortletRequest)externalContext.getNativeRequest() ;
            		HttpServletRequest rawRequest = null;
                    PortletInvocation invocation = (PortletInvocation)request.getAttribute("org.jboss.portal.attribute.component_invocation");
                    if (invocation != null) {
                        rawRequest = (HttpServletRequest) invocation.getDispatchedRequest();
                    }
                    HttpServletRequest outerRequest = rawRequest;
                    while(outerRequest instanceof HttpServletRequestWrapper) 
                    {
                        outerRequest = (HttpServletRequest)((HttpServletRequestWrapper)outerRequest).getRequest();
                    }
                    String flo = outerRequest.getParameter("flo");
                    if(flo==null)
            			nflow = "";
                    else
                    	nflow = flo;
            		return this;
            	}
            This way I get the url parameter from the url which was called externally and is of the form

            localhost:8080/portal/portal/default/Login/PSD+LoginWindow?flo=recovery

            Beautiful! Thank you so much for your help.

            Comment


            • #7
              Code:
              <evaluate expression="flowNames.setNflow(requestParameters.flo)"/>
              
              public Flows setNflow(String flo) {
                      if(flo==null)
              			nflow = "";
                      else
                      	nflow = flo;
              	return this;
              }
              Did you try the above? What was the error?

              Comment


              • #8
                Re:

                No Error. I tried that initially and just got a null value. The request parameter map was null too. That would work if it was only based on portlets as I understand. Adding webflow to the mix causes a subsequent set of request wrappers around it which is why I started with the externalContext and went all way to the "outermost" request to get the url parameters.

                Comment


                • #9
                  I am using requestParameters to get. But I am doing post not get. But it should work. I am using WebLogic Portal 10.3 & SWF 2.1.0. What is your environment?

                  Anyway it is working for you as a outer request. But I want to make cleaner code

                  Comment


                  • #10
                    I agree your code is cleaner. I am using JBoss (2.7.1 I think). I cant use post since the url parameters are embedded in a link and emailed to the user . And when I tried using requestParameters there I got a null object (for the map and any specific parameters) too.

                    Comment

                    Working...
                    X