-4
在我的春節,3.1.2.RELEASE
應用程序,我有一個複雜的形式需要預定豆的注入:注入數據Spring表單
<util:map id="predefinedLocations" map-class="java.util.LinkedHashMap">
<entry key="first address" value="Location A" />
<entry key="another one" value="Location B" />
<!-- ... -->
</util:map>
我創建窗體如下:
@RequestMapping(value = "/create", method = RequestMethod.GET)
public CreationForm createForm() {
return new CreationForm();
}
我無法將地圖作爲我的窗體的構造函數參數傳遞,因爲我的控制器使用了@Valid
註釋,它試圖實例化窗體。
@RequestMapping(value = "/create", method = RequestMethod.POST)
public String create(@Valid CreationForm form, BindingResult formBinding, Model model) {
if (formBinding.hasErrors()) {
// PROBLEM HERE
//
// View rendering fails because a freshly created CreationForm will be
// passed to the view so Spring needs to handle the injection of
// predefinedLocations.
return null;
}
// ...
}
我的第一個想法是使用表單工廠,但在這種情況下我無法實現。
我怎樣才能注入(或參考)的predefinedLocations
豆成我的形式?