简体   繁体   English

Spring Web Flow模型绑定到不同的请求参数

[英]Spring Web Flow Model Binding to different Request Parameters

TL;DR - Is there a way in the model binding within Spring Web Flow to map HTTP Request Parameters to the model property? TL; DR-Spring Web Flow中的模型绑定中是否可以将HTTP请求参数映射到model属性?

The Problem: 问题:

My Spring Web Flow application is accessed through a 3rd party product. 我的Spring Web Flow应用程序是通过第三方产品访问的。 Our clients connect to the external product, do some things, and then requests from the 3rd party product are sent into our web flow. 我们的客户连接到外部产品,执行某些操作,然后将来自第三方产品的请求发送到我们的Web流中。 We then send responses back which tell the external platfrom what to do next. 然后,我们将响应发送回去,该响应告诉外部平台下一步该做什么。

Because of this, I do not have control over the HTTP request parameters that are being sent, however I still am trying to leverage Spring Web Flow binding. 因此,我无法控制正在发送的HTTP请求参数,但是我仍在尝试利用Spring Web Flow绑定。

Model Object 模型对象

public class MyModel {
    private String _value;
    public void setValue(String value);
    public String getValue();
}

Flow Snippet 流程片段

<?xml version="1.0" encoding="utf-8"?>
<flow>
    <on-entry>
        <evaluate expression="new MyModel()" result="flowScope.myModel" />
    </on-entry>
    <view-state id="myForm" model="myModel">
        <binder>
            <binding property="value" converter="my_converter" required="true" />
        </binder>
        <transition on="submit" to="confirm" />
    </view>
</flow>

However, when the actual HTTP request is passed in for submission, the request parameters look like: 但是,当传递实际的HTTP请求进行提交时,请求参数如下所示:

http://web-foo/my-flow?execution=e1s1&_eventId_submit=Submit&Content=ClientValue

Is there any way, outside of using custom actions etc to tell the binder that I want it to grab the value of the HTTP Request Parameter Content and set it on the value property on my Model Object. 除了使用自定义动作等告诉绑定器我希望它获取HTTP请求参数内容并将其设置在我的模型对象的value属性上之外,还有什么方法吗? Future requests will re-use the same HTTP parameter, so I can't just update my model because the value will keep getting overwritten 将来的请求将重新使用相同的HTTP参数,所以我不能仅更新模型,因为该值将不断被覆盖

create an input in your flow: 在流程中创建输入:

<input name="Content" type="string"/>

it will be filled with the request parameter automatically. 它会自动填充request参数。

then simply set it on your model: 然后只需在模型上进行设置即可:

<on-entry>
    <evaluate expression="new MyModel()" result="flowScope.myModel" />
    <set name="myModel.value" value="Content"/>
</on-entry>

... ...

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

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