I need to pass a bean object from MVC to webFlow. Currently, I am achieving it this way:

  1. Storing my bean object as request attribute in controller.
  2. Forwarding to flow.
  3. Accessing the object from flowRequestContext on-start of my flow and setting it in flowScope.

    @RequestMapping(value = "/ProcessUser", method=RequestMethod.POST)
    public String processForm(LoginUser loginUser, HttpServletRequest request){
    ....
    request.setAttribute("registrationDetails", registrationDetails);
    
    return "forward:/chineseFlow";    //Call to flow
     }
    

chineseFlow.xml

  <on-start>        
    <evaluate expression="userDetailsService.getRegistrationDetails(flowRequestContext)" result="flowScope.registrationDetails"/> 
  </on-start>   

UserDetailsService

   public RegistrationDetails getRegistrationDetails(RequestContext requestContext){

    HttpServletRequest httpRequest = (HttpServletRequest) requestContext.getExternalContext().getNativeRequest();
    RegistrationDetails registrationDetails = (RegistrationDetails)httpRequest.getAttribute("registrationDetails");
    return registrationDetails;
}

I don't want to pass multiple request parameters as input to my flow. Is this the correct way to pass the bean to SWF or is there any other better way to achieve the same?

有帮助吗?

解决方案

There are not many options. Proper way would be to redesign your application so that whole process happens within the same flow, then you can store your values in flowscope to begin with. The only alternatives would be either a request attribute (which you are doing already), or session-scoped bean/session attribute. Out of these request attribute(s) is preferred as otherwise you will end up polluting your session scope, and introduce potential bugs that stem from leftover values in session scope.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top