如何根据从第一个选择标签中选择的值填充第二个struts2选择标签?

时间:2018-11-22 09:22:09

标签: java select struts2 dropdown populate

我要在struts2中填充3个选择(区域,站点,部门)。
每个下拉菜单根据上一个下拉菜单中选择的值显示各种选项:

  1. 第一个字段是区域。用户将从区域选择中选择一个区域。
  2. 基于此选定区域,将从数据库中填充站点选择。 用户可以在此处选择多个电台。
  3. 基于这些选定的工作站,将从数据库中填充部门选择标签。 用户可以在此处选择多个部门。

我能够在页面加载时填充区域选择(下拉)并将其显示到jsp页面。 但是,即使stationList属性是从数据库中填充的,站点选择也不会显示在我的页面上。
手动设置也无济于事。

此处的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类。 populateZoneList工作正常,我能够显示数据库中的不同区域。捕获所选值,并将其发送到populateStationSelect()。如果函数中的注释部分未注释,则stationList Map变量包含站点代码和名称的列表。

但是在jsp之后,在Station选择标签中仅显示“ Please Select”标题值。不显示从数据库检索到的站号和名称。 我还为这些映射变量编写了getter和setter方法。

0 个答案:

没有答案