1. s:select 获取list的值

   1) action中书写,为plist提供set,get方法

    private List<Post> plist;      

    plist=service.queryPost();
        //通过岗位查询应聘者
        list = service.getperlist(post_id,can_status,sxorder);
       
          HttpServletRequest request = ServletActionContext.getRequest();
          request.setAttribute("postId", post_id);
          request.setAttribute("can_status", can_status);
          request.setAttribute("sortorder", sxorder);

      2) 页面jsp迭代

     <td style="padding-left: 240px">岗位名称:
    <s:select list="plist" listKey="id" listValue="name" headerKey="" headerValue="请选择岗位" id="Post_id" onchange="selectPost()" value="%{#request.postId}"></s:select>                      
         </td>

list为action传递过来plist ,listKey为post对象的id属性,listValue 为post对象的name属性 ,value 为下拉框的默认值。action把postId存到request区域,页面struts取值为value="%{#request.postId}"

 

2. jsp取枚举值

<td>状态:
                     <s:select list="@com.nazca.rtms.common.consts.CandidateState@values()" listKey="name()" listValue="toString()" headerKey="" headerValue="请选择状态" id="Status_id" onchange="selectStatus()" value="%{#request.can_status}"></s:select>
                 </td>

list为枚举的类名,value属性为下拉框的默认值 value="%{#request.can_status}"从request区域获得。

 

jsp页面也可以采用jquery的方式获取下拉框的默认值

   获取下拉框的id,把下拉框的默认值设置为action传递过来的值即可。

               $(document).ready(function(){  
                 var sel = document.getElementById("Post_id");
                 sel.value='${postId}';
                 
                 var status = document.getElementById("Status_id");
                  status.value='${can_status}';
            });

 

 以下的摘录自网络

 

枚举定义的方式:
一、无定义索引index
public enum TypeEnum {
  PURRET("采购单退货"),
  BADGOODS("滞销退货"),
  BADSELL("次品退货");
 
  private String message;
 
private TypeEnum(String message) {
this.message = message;
}
public String toString(){
return this.message;
}
}
在<s:select/>中使用:<s:select list="@包名.类名@values()" listKey="name()" listValue="toString()">
listKey是值,listValue是下拉框中显示的名字。
枚举在下拉框中的默认值,设置下拉框的value属性,如:
<s:select list="@cn.com.winchance.skystore.domain.purchase.OrderTypeEnum@values()" listKey="name()" listValue="toString()" id="type" value="@cn.com.winchance.skystore.domain.purchase.OrderTypeEnum@SELF.name()"/> SELF是指枚举中的一个选项。
在js中修改枚举下拉框的值:document.getElementByIdx_x("type").value="PROXY";PROXY是该枚举中的一个选项。
从action中传递过来的值作为下拉框的默认选中值:
action中:request.setAttribute("orderType",orderType);  //orderType是一个枚举类对象
页面中:<s:select cssStyle="width:100px" name="orderType" id="orderType"        list="@cn.com.winchance.skystore.domain.purchase.OrderTypeEnum@values()" listKey="name()"  listValue="toString()" value="%{#request.orderType.name()}" //struts标签通过%{#request.orderType.name()}给下拉框赋默认值。
 
二、定义了索引index descrition
 
public enum ServeLevelEnum {
COMMON(0,"普通"),
EMERGENCE(1,"紧急");
private final Integer index;
private final String description;
 
private ServeLevelEnum(Integer index, String description) {
this.index = index;
this.description = description;
}
 
public Integer getIndex() {
return index;
}
 
public String getDescription() {
return description;
}
}
无使用心得
 
三、后台action中传到页面的list
<s:select name="chk_compact" list="compactsList" listKey="id" listValue="comname" headerKey="0" headerValue="请选择" cssStyle="width:115px" />
其中compactList从后台得到,后台必须有setter和getter方法。listKey为值,listValue为下拉框显示信息。
listValue必须是compactList的实体元素中的一个字段名。