我在将模型绑定(bind)到表单 View 时遇到问题,出现错误
在 null 上找不到属性或字段“city”
我正在尝试将String place.location.city
绑定(bind)到我的 View
<form role="form" th:action="${flowExecutionUrl}" th:object="${place}" method="post">
<input class="form-control" th:field="*{location.city}"/>
<!-- ... -->
</form>
这是我遇到错误的子流 xml
<view-state id="mapView" view="/places/add/location" model="place">
<transition on="locationSelected" to="locationReady"/>
</view-state>
<end-state id="locationReady">
</end-state>
最佳答案
错误消息告诉您 Location 或 Place 为空。
如果我不得不猜测您可能没有初始化模型在进入 View 状态mapView之前将模型放置在流程xml中
<set name="flowScope.place" value ="new your.class.path.model.Place()"/>
尽管您可能希望使用工厂方法来初始化 Place(因此您也可以在 1 次调用中初始化 Location)
关于java - 使用 Spring Web Flow 绑定(bind)模型以查看,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33307694/