在Web-Flow中返回对象参数

时间:2013-07-18 12:04:55

标签: java spring spring-webflow

我有以下文件:

的Webflow-context.xml中

...
<bean id="user" class="com.bla-bla.datamodel.User" scope="prototype" />
...

User.java

public class User implements Serializable {
    private static final long serialVersionUID = 1L;
    private Integer id;
    private String name;
    private Address address = new Address();
    //setters and getters
}

addUser.jspx

...
<form:form commandName="user">
        <form:hidden path="id" />
                    <form:input path="name"/>
                    <form:input path="address.street"/>
          <div class="Buttons">
            <div class="Button">
                <button type="submit" name="_eventId_cancelUser">
                    <fmt:message key="button.cancel" />
                </button>
                <button type="submit" name="_eventId_userNext">
                    <fmt:message key="button.next" />
                </button>
            </div>
        </div>
</form:form>
...

addUser.xml

    <on-start>
        <set name="flowScope.user" value="user" />
    </on-start>

    <view-state id="addUser" view="addUser">
        <transition on="cancelUser" to="cancelUser"/>
        <transition on="userNext" to="userNext">
            <set name="user.name" value="requestParameters.name"/>
            <set name="user.address.street" value="requestParameters.address.street"/>
        </transition>
    </view-state>
...

问题是工作正常但有错误:

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.webflow.execution.ActionExecutionException: Exception thrown executing [AnnotatedAction@741dbf43 targetAction = [SetAction@4cf80343 name = user.address.street, value = requestParameters.address.street], attributes = map[[empty]]] in state ' addUser ' of flow ' addUser ' -- action execution attributes were 'map[[empty]]'
org.springframework.webflow.execution.ActionExecutionException: Exception thrown executing [AnnotatedAction@741dbf43 targetAction = [SetAction@4cf80343 name = user.address.street, value = requestParameters.address.street], attributes = map[[empty]]] in state ' addUser ' of flow ' addUser ' -- action execution attributes were 'map[[empty]]'
org.springframework.binding.expression.EvaluationException: An ELException occurred getting the value for expression 'requestParameters.address.street' on context [class org.springframework.webflow.engine.impl.RequestControlContextImpl]
org.springframework.expression.spel.SpelEvaluationException: EL1007E:(pos 0): Field or property 'street' cannot be found on null

如果字段«User»是一个对象,我会收到错误。 我的工作只是将数据输入页面并将其保存在bean用户(flowScope.user)中,这将是处理它们的最后一步。

如何正确做到?

UPD:即使在<form:input path="address.street"/>地址= NULL之后,我也发现了我的问题。但为什么呢?

1 个答案:

答案 0 :(得分:0)

我认为问题在于:value="requestParameters.address.street"

requestParameters只能包含字符串,您希望类型为Address的对象

只需在您的网址中通过您的街道...&name=foo&street=bar...即可 并以requestParameters.street

收到