我正在使用彈簧MVC 4,我試圖填充下拉菜單(選擇選項),但無法找到一種方法使其工作(已花費數小時)。無法填充下拉菜單(選項)
型號:
public class DataFixingModel {
private ArrayList<String> keys;
private String value;
private String keySelected;
public dataFixingModel() {
this.keys = getKeysValues(); //return ArrayList
this.value = "TMP";
this.keySelected = "abc";
}
....
public ArrayList<String> getKeys() {
return keys;
}
....
控制器:
public class DataFixing {
@RequestMapping(value = "/extra/dataFixing/dataFixing", method = RequestMethod.GET)
public String initCreationTask(ModelMap model) throws ParseException {
DataFixingModel dataFixingModel = new DataFixingModel();
ArrayList<String> urls = dataFixingModel.getKeys();
for (String str:urls){
System.out.println("------key:"+str);
}
//it print all the keys as expected
model.addAttribute("dataFixingModel", dataFixingModel);
return "extra/dataFixing/dataFixing";
}
}
JSP:
<form:form modelAttribute="dataFixingModel" method="POST" class="form-horizontal" cellspacing="2" enctype="multipart/form-data">
....
....
<div class="col-md-4">
<form:select class="form-control input-sm" path="keySelected" data-toggle="tooltip" data-placement="left" title="${title}">
<form:option value="0">--Choose Identifier Type--</form:option>
<form:options items="${keys}"/>
</form:select>
</div>
- 「TMP」 應用耳朵在「價值」領域罰款。
- 在其他model-controller-jsp中,下拉列表由請求的鍵填充,但不在上面的model-controller-jsp中填充。
- 我已經嘗試使用array([])而不是arraylist)。
- 在查看源中,選項下沒有鍵。
我做錯了什麼?
感謝, 三木
你在'DataFixingModel'中擁有公共'getter'屬性? –
是的。所有的獲取者/設置者都是公開的... – Mike