如何访问流外的Spring Webflow FlowScope元素? [英] How can I access Spring Webflow FlowScope elements outside the flow?

查看:120
本文介绍了如何访问流外的Spring Webflow FlowScope元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编辑:我没有对这个问题有所了解,所以我添加了一些细节。



我有一个Spring Webflow应用程序(版本2.3) 0.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,你的对象验证失败。);
}
}
}

如你所见,在 Spring Webflow Validator 那里除了你应该验证的对象之外没有任何直接的外部链接。我需要在flowScope中找到其他对象。理想情况是通过 ApplicationContext 或其他一些环境功能必须有一种方法来获取这些其他对象。



任何人都知道答案吗?

解决方案

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

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

RequestContext requestContext = RequestContextHolder.getRequestContext();
requestContext.getFlowScope()。get(objectYouAreLookingFor);


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?

解决方案

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

这篇关于如何访问流外的Spring Webflow FlowScope元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆