Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I access Spring Webflow FlowScope elements outside the flow?

EDIT: I didn't get any bites on this question, so I'm adding a little more detail.

I have a Spring Webflow app (ver 2.3.2). I need to access multiple FlowScope objects from inside the validation of one of the steps (not inside the flow itself). You would think this would be simple, but I haven't been able to crack it.

Spring Webflow provides a series of special EL variables which can be used for accessing the various scopes, but only inside the flow itself. Inside a custom Spring validator, there doesn't seem to be any way to get to them:

@Component
public class MyObjectValidator {

    @Autowired
    ApplicationContext context;

    public void validateMyObject(MyObject myObject, Errors errors) {

        FlowScope flowScope = context.someMagicFunction();  //  <---- UNKNOWN  
        MyOtherObject otherObject = flowScope.get("otherObject");  

        if (incrediblyComplexValidation(myObject, otherObject) {
            errors.rejectValue("myField","validation.fail","Your object failed validation.");
        }
    }
}

As you can see, inside a Spring Webflow Validator there is no direct external linkage to anything except the object you are supposed to validate. I need to get to those other objects in the flowScope. Ideally either through the ApplicationContext or some other environmental feature there must be a way to get to these other objects.

Anyone know the answer to this?

like image 297
user3120173 Avatar asked Mar 17 '14 18:03

user3120173


People also ask

Which view technology can be used to render Spring web MVC view?

18.4 Velocity & FreeMarker Velocity and FreeMarker are two templating languages that can be used as view technologies within Spring MVC applications.

What are the differences between Spring MVC and Spring Web Flow?

MVC is an implementation of the Model View Controller design pattern, webflow is an implementation of a "web flow" state machine. Web flow sits on top of springs MVC and allows you to define complex navigational flows.

Which Spring Web Flow component maps the request to a particular Web Flow?

Configuring Web Flow in Spring. Spring Web Flow is built on a foundation of Spring MVC. That means all requests to a flow first go through Spring MVC's DispatcherServlet . From there, a handful of special beans in the Spring application context must be configured to handle the flow request and execute the flow.

How do I enable Spring Security for web flows?

To enable Spring security for web flows. Explanation: You have to register the flow execution listener SecurityFlowExecutionListener in the flow executor to enable Spring Security for web flow.


1 Answers

You can get the scope beans from RequestContext - context holder for request-specific statecurrent web application context. Access to request context in your validator method is by:

    import org.springframework.webflow.execution.RequestContext;
    import org.springframework.webflow.execution.RequestContextHolder;

    RequestContext requestContext = RequestContextHolder.getRequestContext();
    requestContext.getFlowScope().get("objectYouAreLookingFor");
like image 99
Prasad Avatar answered Sep 29 '22 17:09

Prasad