简体   繁体   English

我可以在Spring MVC控制器中获取当前的webflow状态吗?

[英]Can I get the current webflow state within a Spring MVC controller?

On the surface, a bit of a strange question! 表面上,有一个奇怪的问题! but I am creating a web app that uses both webflow and traditional Spring MVC controllers. 但是我正在创建一个同时使用webflow和传统Spring MVC控制器的Web应用程序。

From one of the webflow views, a http request (ajax) is made from the client to a spring controller. 从其中一个Webflow视图中,从客户端向Spring控制器发出http请求(ajax)。 When this was originally coded it didnt have much of a logical connection to the webflow, but now things have moved on and the controller could really do with knowing what screen (view-state) the request has come from. 最初进行编码时,它与Webflow并没有很大的逻辑联系,但是现在事情已经发展了,控制器可以真正地知道请求来自哪个屏幕(视图状态)。

My controller method signature looks like this: 我的控制器方法签名如下所示:

@RequestMapping(value="/AjaxStuff", method=RequestMethod.POST)
public String ajaxStuff(@ModelAttribute("quote") QB2MotorQuote p_quote, BindingResult p_bindingResult, 
        HttpServletRequest p_req, Model p_model, DefaultMessageContext p_messages) {

I know from some of my webflow action classes that I can get the current state from the RequestContext object: 我从一些webflow动作类中知道,我可以从RequestContext对象获取当前状态:

public Event checkDeclines(RequestContext p_ctx) throws Exception {
    // get the current state
    StateDefinition state = p_ctx.getCurrentState();

I've never really understood the 'voodoo' :) that Spring does where it can automagically inject parameters just by specifying them on the method signature (surely it can only inject things it knows about ??). 我从来没有真正理解过'voodoo':) Spring可以通过仅在方法签名上指定参数来自动注入参数(当然,它只能注入它知道的??)。 I've tried simply changing the method signature of my controller method to inject in the RequestContext (in the vain hope that it will get injected), but it doesn't. 我已经尝试过简单地更改控制器方法的方法签名以将其注入RequestContext中(徒然希望将其注入),但事实并非如此。 It complains that RequestContext is an interface. 它抱怨RequestContext是一个接口。

So, does anyone know how I can make my controller know about the current webflow state - either through injecting something into the controller method signature, or perhaps I can get it from the http request somehow (or session, which I can get from the request). 因此,有谁知道我如何使我的控制器了解当前的Webflow状态-通过将某些内容注入到控制器方法签名中,或者我可以以某种方式从http请求(或会话,可以从请求中获取)中获取它)。

Any help with this very much appreciated. 非常感谢任何帮助。

inside your webflow view, you should have access to a variable ${flowRequestContext} that you can use in your ajax call. 在您的webflow视图中,您应该有权访问可在ajax调用中使用的变量${flowRequestContext}

you can just get the piece of information ${flowRequestContext.currentState} you want from it and add it as a parameter. 您可以从中获取所需的信息${flowRequestContext.currentState}并将其添加为参数。

you cannot have the requestContext directly injected as your are not in a webflow environment. 您不能直接注入requestContext,因为您不在Webflow环境中。 If you were, you could directly use RequestContext.getRequestContext() . 如果您是的话,可以直接使用RequestContext.getRequestContext() Try calling it from your MVC controller and you will get null. 尝试从您的MVC控制器调用它,您将得到null。 Try from within a flow and you will get it. 从流程中尝试,您将得到它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM