一、 级联下拉列表(以行业大类和详细类为例)
主要实现思路:
主下拉列表(行业大类) 发生onchange事件时调用action查询次下拉列表
具体实现:
1. jsp页面
脚本:
<script type="text/javascript">
function changeIndustry(industryId) {
location.href("addJobView2?industryId="+industryId);
}
</script>
表单:
代码如下:
<!-- 级联下拉列表 -->
<td>
<s:select label="职业类别" name="job.industry.industryId" id="job.industry.industryId" list="#session.IndustryList" listValue="industryName" listKey="industryId" headerKey="0" headerValue="--请选择--" onchange="changeIndustry(this.value)" value="#request.IndustryId" />
</td>
</tr>
<tr>
<td>
<s:if test="#request.IndustryDetailList==null">
<s:select name="job.industryDetail.industryDetailId"
list="{'--请选择--'}"></s:select>
</s:if>
<s:else>
<s:select name="job.industryDetail.industryDetailId"
id="job.industryDetail.industryDetailId"
list="#request.IndustryDetailList"
listValue="industryDetailName" listKey="industryDetailId"
headerKey="0" headerValue="--请选择--" />
</s:else>
</td>
2. action类
代码:
public String addJobView(){//发布职位 首先要得到所有分类
List IndustryList=IndustryService.findAll();
Map session=(Map) ActionContext.getContext().getSession();
session.put("IndustryList", IndustryList);//保存在request 在页面获取
return SUCCESS;
}
public String addJobView2(){//发布职位 级联下拉列表 得到分类详细
List IndustryDetailList=IndustryDetailService.findByIndustryId(industryId);
Map request=(Map) ActionContext.getContext().get("request");
request.put("IndustryDetailList", IndustryDetailList);
request.put("industryId", industryId);
//System.out.println("ssssss");
return SUCCESS;
}
3. struts.xml
代码:
<package name="default" extends="struts-default" namespace="/wjq_zp">
<action name="addJobView" class="jobAction" method="addJobView">
<result name="success">addjob.jsp</result>
</action>
<action name="addJobView2" class="jobAction" method="addJobView2">
<result name="success">addjob.jsp</result>
</action>
</package>