绑定模型以使用 Spring Web Flow 查看

Binding model to view with Spring Web Flow

我在绑定模型以形成视图时遇到问题,我收到错误

Property or field 'city' cannot be found on null

我正在尝试将 String place.location.city 绑定到我的视图

<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 为空。

如果我不得不猜测您可能没有初始化模型 将模型放入流程中 xml 进入视图状态 mapView

之前
<set name="flowScope.place" value ="new your.class.path.model.Place()"/>

尽管您可能希望使用工厂方法来初始化 Place(因此您也可以在 1 个调用中初始化 Location)