从表面上看,有点奇怪的问题!但我正在创建一个同时使用 webflow 和传统 Spring MVC Controller 的 Web 应用程序。
从其中一个 webflow View 中,客户端向 spring Controller 发出了一个 http 请求 (ajax)。当这最初被编码时,它与 webflow 没有太多逻辑联系,但现在事情发生了变化, Controller 真的可以知道请求来自哪个屏幕( View 状态)。
我的 Controller 方法签名如下所示:
@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) {
我从我的一些 webflow 操作类中知道我可以从 RequestContext 对象获取当前状态:
public Event checkDeclines(RequestContext p_ctx) throws Exception {
// get the current state
StateDefinition state = p_ctx.getCurrentState();
我从来没有真正理解过 Spring 所做的“巫术”:它可以通过在方法签名上指定参数来自动注入(inject)参数(当然它只能注入(inject)它知道的东西 ??)。我试过简单地更改我的 Controller 方法的方法签名以注入(inject) RequestContext(徒劳地希望它会被注入(inject)),但事实并非如此。它提示 RequestContext 是一个接口(interface)。
那么,有没有人知道我如何让我的 Controller 知道当前的 webflow 状态——通过在 Controller 方法签名中注入(inject)一些东西,或者我可以以某种方式从 http 请求(或 session ,我可以得到)来自请求)。
非常感谢对此的任何帮助。
最佳答案
在您的 webflow View 中,您应该有权访问可在 ajax 调用中使用的变量 ${flowRequestContext}
。
您可以从中获取您想要的信息${flowRequestContext.currentState}
并将其添加为参数。
您不能直接注入(inject) requestContext,因为您不在 webflow 环境中。如果是,您可以直接使用 RequestContext.getRequestContext()
。尝试从您的 MVC Controller 调用它,您将得到 null。从流程中尝试,您会得到它。
关于java - 我可以在 Spring MVC Controller 中获取当前的 webflow 状态吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12096018/