struts2中的<s:select>默认选项
//... public class SelectAction extends ActionSupport{ private List<String> searchEngine; private String yourSearchEngine; //set default value public String getDefaultSearchEngine() { return "yahoo.com"; } public SelectAction(){ searchEngine = new ArrayList<String>(); searchEngine.add("google.com"); searchEngine.add("bing.com"); searchEngine.add("yahoo.com"); searchEngine.add("baidu.com"); } //... }
<s:select>标记呈现HTML下拉框。value=“defaultSearchEngine”将调用对应动作类的getDefaultSearchEngine()方法返回一个默认搜索引擎的值。
<s:select label="What's your favor search engine" headerKey="-1" headerValue="Select Search Engines" list="searchEngine" name="yourSearchEngine" value="defaultSearchEngine" />
在这个例子中,下拉框将自动选择“yahoo.com”作为默认选项。