java如何根据从第一个select标记中选择的值填充第二个struts2 select标记?
我想在struts2中填充3个选项(区域、车站、部门)
每个下拉列表根据在上一个下拉列表中选择的值显示各种选项:
- 第一个领域是区域。用户将从区域选择中选择单个区域李>
- 基于此选定区域,将从数据库中填充station select。 用户可以在此处选择多个电台李>
- 基于这些选定的站点,将从数据库中填充部门选择标签。 用户可以在此处选择多个部门李>
我能够在页面加载时填充区域选择(下拉),并将其显示到jsp页面。
然而,即使从数据库填充stationList
属性,我的页面上也不会显示station select
手动设置也无济于事
JSP代码如下:
<tr>
<td style="background-color:#FFFFFF;" class="headingLabelStyle1" align="right">
<s:label value="Zone" ></s:label></td>
<td width="4%" align="center" class="headingLabelStyle1" style="background-color:#FFFFFF;">
<s:label value=":" /> </td>
<td style="background-color:#FFFFFF;">
<s:select name="pmrkpr8800Bean.zone" list="zoneList" id="zone"
headerValue="-- Please Select --" headerKey="-1"
tabindex="1" cssClass="h1"></s:select>
</td>
</tr>
<tr>
<td style="background-color:#FFFFFF;" class="headingLabelStyle1" align="right">
<s:label name="stncd" value="Station Code" ></s:label></td>
<td width="4%" align="center" class="headingLabelStyle1" style="background-color:#FFFFFF;">
<s:label value=":" /> </td>
<td style="background-color:#FFFFFF;">
<s:select name="pmrkpr8800Bean.stnCde" list="stationList" id="stnCde" headerValue="-- Please Select --" headerKey="-2" tabindex="2" cssClass="h1" size="3" multiple="true"></s:select>
</td>
</tr>
<tr>
<td style="background-color:#FFFFFF;" class="headingLabelStyle1" align="right">
<s:label value="Department" ></s:label></td>
<td width="4%" align="center" class="headingLabelStyle1" style="background-color:#FFFFFF;">
<s:label value=":" /> </td>
<td style="background-color:#FFFFFF;">
<s:select name="pmrkpr8800Bean.dept" list="deptList" id="dept" headerValue="-- Please Select --" headerKey="-1" tabindex="3" cssClass="h1" size="3" multiple="true"></s:select>
</td>
</tr>
public String populateZoneSelect() {
String result = SUCCESS;
try {
log.info("Inside populateZoneSelect");
zoneList = ipmrkpr8800.getZoneList();
} catch (Exception e) {
result = ERROR;
e.printStackTrace();
}
return result;
}
public String populateStationSelect() {
String result = SUCCESS;
String selZone = request.getParameter("selZone");
System.out.println("Selected zone: " + selZone);
try {
stationList.put("CSMT", "CSMT-MUMBAI");
stationList.put("NDL", "NDL-NEW DELHI");
stationList.put("PNVL", "PNVL-PANVEL");
} catch (IOException e) {
e.printStackTrace();
}
/*try {
log.info("Inside populateStationSelect");
stationList = ipmrkpr8800.getStationList(selZone);
System.out.println("StationList: " + stationList.size());
} catch (Exception e) {
result = ERROR;
e.printStackTrace();
}*/
return result;
}
最后两个代码块来自Action类。PopulationOneList运行良好,我能够显示数据库中的不同区域。所选值被捕获并发送到PopulationSelect()。如果函数中已注释的部分未注释,stationList Map变量将包含站点代码和名称的列表
但在jsp中,在Station select标记中只显示“请选择”标题值。不显示从数据库检索到的车站代码和名称。 我也为这些映射变量编写了getter和setter
共 (0) 个答案