「Struts2入門」selectタグの使い方

1.htmlコード
<form>
<select name=”name”>
<option value=”v1″>test data v1</option>
<option value=”v2″>test data v2</option>
</select>
</form>

2.Actionコード
public class ConfigCustomerInfoAction extends ActionSupport {
private List<CustomerInfo> typeList = new ArrayList<CustomerInfo>();
public String execute()throws Exception{
CustomerInfo cstInfo = new CustomerInfo();
cstInfo.setTypeName(“normal”);
cstInfo.setTypeValue(“一般ユーザ”);
typeList.add(cstInfo);
CustomerInfo info2 = new CustomerInfo();
info2.setTypeName(“special”);
info2.setTypeValue(“管理ユーザ”);
typeList.add(info2);
return SUCCESS;

}
public List<CustomerInfo> getTypeList() {
return typeList;
}
public void setTypeList(List<CustomerInfo> typeList) {
this.typeList = typeList;
}
}

3.struts.xmlコード
<action name=”configCustomerInfo” class=”org.startnews.action.ConfigCustomerInfoAction”>
<result>/getCustomerInfo.jsp</result>
</action>

4.CustomerInfoクラスの定義
public class CustomerInfo {
private String typeName;
private String typeValue;
public String getTypeName() {
return typeName;
}
public void setTypeName(String typeName) {
this.typeName = typeName;
}
public String getTypeValue() {
return typeValue;
}
public void setTypeValue(String typeValue) {
this.typeValue = typeValue;
}

}

5.JSPコード
<s:select list=”typeList” name=”type” listKey=”typeName” listValue=”typeValue” label=”ユーザ権限”></s:select>