我有以下文件:
webflow-context.xml
...
<bean id="user" class="com.bla-bla.datamodel.User" scope="prototype" />
...
用户.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>
...
添加用户.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 之后。但为什么?