1、Action类
public class AppsAction extends ActionSupport {
private App app;
private Service appsService;
//省略getter,setter
}
2、bean
public class Category implements Serializable {
private Long ID; //ID
private String categoryId; //ID
private String parentId; //父类别ID
private String categoryName; //类别名称
private Integer status; // 状态:0,生效 1,失效
//省略getter,setter
}
2、JSP页面
<s:action name="appcatelist" ignorecontextparams="true" executeresult="false"
namespace="/service"> </s:action>
<!-- struts2 其他标签组合的生成方式 -->
<select name="app.categoryId"> <option>全部</option>
<s:iterator value="%{#request.appcatelist}" status="st" id="caList">
<s:if test="app.categoryId==categoryId ">
<option value="<s:property value='categoryId' />" selected="selected">
<s:property value="categoryName" />
</option>
</s:if>
<s:else>
<option value="<s:property value='categoryId' />">
<s:property value="categoryName" />
</option>
</s:else>
</s:iterator>
</select>
<!-- s:select 标签 不能设置我想要的“全部” 这个项-->
<s:select name="app.categoryId" list="%{#request.appcatelist}" headerKey="%{app.categoryId}" headerValue="%{#request.cataName}" listKey="categoryId" listValue="categoryName"></s:select>
说明:用过<s:select>标签,你会发现,这个标签其实没那么好用,不太灵活:
(1)s:select设置默认选择项,不太好看。
(2)s:select没办法设置一个在 上述代码中%{#request.appcatelist} 这个list中没有的项,也就是上面的“全部” 这个选择项。
所以花了点时间想了一下,用struts2其他标签来生成动态的下拉选择框。