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

ぃ、小莉子 提交于 2019-11-30 05:31:04

问题


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?


回答1:


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");


来源:https://stackoverflow.com/questions/22462077/how-can-i-access-spring-webflow-flowscope-elements-outside-the-flow

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!