我正在使用spring MVC 4,我正在尝试填充下拉菜单(select-options),但找不到让它工作的方法(已花费数小时)。
型号:
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>
我做错了吗?
谢谢, 三木
答案 0 :(得分:0)
如果你有这个吸气剂:
public ArrayList<String> getOpenUrlKeys() {
return openUrlKeys;
}
您将获得<form:options items="${openUrlKeys}"/>
但没有多大意义,因为我无法看到声明的openUrlKeys变量... getKeys()
应使用<form:options items="${keys}"/>
答案 1 :(得分:0)
我找到了解决方案:
我换了:#!/bin/bash
DB_NAME=ex3.sqlite
DB_TABLE=t1
sqlite3 $DB_NAME << EOF
DROP TABLE IF EXISTS $DB_TABLE;
CREATE TABLE $DB_TABLE (
"f1" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
"f2" TEXT NOT NULL DEFAULT "f2-text"
);
INSERT INTO $DB_TABLE (f1, f2) VALUES (1, "text 1");
INSERT INTO $DB_TABLE (f1, f2) VALUES (2, "text 2");
EOF
用:<form:options items="${keys}"/>
。
谢谢大家! 麦克