【问题标题】:How to populate a <s:select> box according to the selected value of the another <s:select> box如何根据另一个 <s:select> 框的选定值填充 <s:select> 框
【发布时间】:2013-10-30 09:21:13
【问题描述】:

我的 jsp 页面中有两个 struts2 选择框。第一个选择框由一个在服务器端设置值的对象填充。

这个对象有两个元素:

String softwareName;
Map<String,String> versionList;

第一个选择框由该对象填充。此选择框的 Listkey 属性使用 versionList,此选择框的 ListValue 使用 softwareName。像这样:

<s:select name="listSoftware" list="listSoftware" listkey="versionList" listvalue="softwareName">

于是html中的选择框变成了这样:

<select name="listSoftware">
    <option value="DummySoftware-1.0.0=1.0.0,DummySoftware-2.0.0=2.0.0,DummySoftware-3.0.0=3.0.0">DummySoftware</option>
    <option value="TestSoftware-4.0.0=4.0.0,TestSoftware-5.0.0=5.0.0,TestSoftware-6.0.0=6.0.0">TestSoftware</option>
    <option value="CheckSoftware-7.0.0=7.0.0,CheckSoftware-8.0.0=8.0.0,CheckSoftware-9.0.0=9.0.0">CheckSoftware</option>
</select>

现在我想根据从第一个选择框中选择的软件填充第二个选择框。例如,如果用户从第一个选择框中选择 DummySoftware,则应在第二个选择框中填充相应版本的 DummySoftware,即 1.0.0、2.0.0 和 3.0.0。

有人可以帮忙吗?

【问题讨论】:

    标签: javascript struts2 html-select


    【解决方案1】:

    你可以使用doubleselect

    Reference

    动作

    private List<BeanFirst> lstFirst = new ArrayList<BeanFirst>();
    
    public String execute() {
        List<BeanSecond> lstSecond = new ArrayList<BeanSecond>();
        lstSecond.add(new BeanSecond(1, "sec1"));
        lstSecond.add(new BeanSecond(2, "sec2"));
    
        List<BeanSecond> lstSecond2 = new ArrayList<BeanSecond>();
        lstSecond2.add(new BeanSecond(3, "sec3"));
        lstSecond2.add(new BeanSecond(4, "sec4"));
    
    
        BeanFirst f1 = new BeanFirst(1, "name1", lstSecond);
        BeanFirst f2 = new BeanFirst(22, "name2", lstSecond2);
        lstFirst.add(f1);
        lstFirst.add(f2);
    
        return SUCCESS;
    }
    

    BeanFirst.java

    public class BeanFirst
    {
        private Integer id;
        private String name;
        private List<BeanSecond> lst;
    
    //Getters & Setters
    }
    

    BeanSecond.java

    public class BeanSecond
    {
        private Integer id;
        private String name;
    
       //Getters & Setters
        }
    

    JSP

    <s:doubleselect list="lstFirst" listKey="id" listValue="name" name="idfirst" doubleList="lst" doubleName="idsecond" doubleListKey="id" doubleListValue="name" label="Double Select Here"/>
    

    【讨论】:

      【解决方案2】:

      这样的事情是您想要的,但您想要做的是从一个验证,然后生成您的 result.jsp,其中两个选择再次使用现在预填充的版本。所以基本上添加一个jsp到这个。 http://www.mkyong.com/struts2/struts-2-sselect-drop-down-box-example/

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-12-04
        • 1970-01-01
        相关资源
        最近更新 更多