如何访问流外的Spring Webflow FlowScope元素?

use*_*173 5 java spring spring-webflow-2

编辑:我没有对这个问题有所了解,所以我补充一点细节.

我有一个Spring Webflow应用程序(版本2.3.2).我需要从其中一个步骤(不在流程本身内部)的验证中访问多个FlowScope对象.你会认为这很简单,但我无法破解它.

Spring Webflow提供了一系列特殊的EL变量,可用于访问各种范围,但仅限流本身.在自定义Spring验证器中,似乎没有任何方法可以访问它们:

@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.");
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

正如您所看到的,在Spring Webflow Validator中,除了您应该验证的对象之外,没有任何直接的外部链接.我需要访问flowScope中的其他对象.理想情况下,无论是通过ApplicationContext其他环境特征还是其他环境特征,都必须有一种方法来获取这些其他对象.

有人知道答案吗?

Pra*_*sad 15

您可以从RequestContext获取范围bean - 用于特定于请求的状态当前Web应用程序上下文的上下文持有者.在验证方法中访问请求上下文是:

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

    RequestContext requestContext = RequestContextHolder.getRequestContext();
    requestContext.getFlowScope().get("objectYouAreLookingFor");
Run Code Online (Sandbox Code Playgroud)