Struts2标签-select实用方法

struts2 s:select 标签
1 静态生成
[html] view plain copy print?
select name="user.sex" list="#{'0':'男','1':'女'}" label="性别" headerKey="" headerValue="请选择性别">select>  

注解:这里从页面来静态(也就是在页面中写死啦)构造下拉选项,关键点是list="#{'0':'男','1':'女'}" 通过它实现的select的两个option 。headerKey指定缺省的选项"key",headerValue指定缺省的选项"value"2.设置下拉框数据源
[html] view plain copy print?
<%  
        java.util.HashMap map = new java.util.LinkedHashMap();  
        map.put(1, "aaa");  
        map.put(2, "bbb");  
        map.put(3, "ccc");  
        request.setAttribute("map", map);  
        request.setAttribute("aa", "2");  
%>  
[html] view plain copy print?
select list="#request.map"  label="abc" listKey="key" listValue="value" value="#request.aa"  headerKey="0" headerValue="aabb">  
select>  




value的值设置为了2,所以初始化下拉框时,会自动选择key值为2的选项



3.action传递list过来
[java] view plain copy print?
public class Program implements Serializable {  
    /**    serialVersionUID */  
    private static final long serialVersionUID = 1L;  
    private int programid;  
    private String programName;  
    public int getProgramid() {  
        return programid;  
    }  
    public void setProgramid(int programid) {  
        this.programid = programid;  
    }  
        public String getProgramName() {  
        return programName;  
    }  
    public void setProgramName(String programName) {  
        this.programName = programName;  
    }  
}  

action
[java] view plain copy print?
xxxAction extends  extends ActionSupport {  
    private  List programs ;//list集合  
       public List getPrograms() {  
        return programs;  
    }  
    public void setPrograms(List programs) {  
            this.programs = programs;  
    }  
}  
jsp页面
[html] view plain copy print?
select list="programs "  listValue="programName " listKey="programid "  name="program" id="program"  
           headerKey="0l" headerValue="" >  
select>    

listKey说明下拉框的key值对应 programid字段,listValue说明下拉框的显示部分对应programName字段
 
"goodsBillList.action" method="post" > 请选择区域: type="submit" value="查询" />
通过name向后台传递value 要提交的,都需要写form
"queryBook.action" method="post"> "chaxunName" type="text" /> type="submit" value="查询" />

你可能感兴趣的:(Struts2)