简体   繁体   English

如何使用另一个列表框java struts添加值列表框?

[英]how to add value listbox with another listbox java struts?

i want to use two listbox (multiple) on java struts enviroment. 我想在java struts环境中使用两个列表框(多个)。 first listbox is listed personel names and second listbox is blank at first. 第一个列表框列出了人员名称,第二个列表框起初为空白。 With add and remove buttons fill up second listbox with value from selected first listbox. 使用“添加”和“删除”按钮,用选定的第一个列表框中的值填充第二个列表框。 But i don t know how to use this? 但是我不知道该怎么用?

value is string array or collection to getter/setter? 值是字符串数组还是要获取/设置的集合? and how to use? 以及如何使用?

furthermore i know javascript code how is making but struts is complex. 此外,我知道javascript代码的制作方式,但struts很复杂。

my code is: 我的代码是:

JSP : JSP:

first listbox and second listbox 第一个列表框和第二个列表框

< td class="formitem">
    < html:select multiple="true" size="4" styleClass="textField" >
        < html:options collection="pName" property="deger" labelProperty="pers"/>
    </html:select>
</td>

 <td class="formitem">
    <html:select property="personelName" styleClass="textField" >
        <html:options collection="personelList" property="deger" labelProperty="xxx"/>
    </html:select>  
 </td>

my form code is 我的表格代码是

private String[] pName = null;  is string array or another type?

public String[] getpName() {
    return pName;
}

public void setpName(String[] pName) {
    this.pName = pName;
}

model class 模型类

public static Collection personelFill(String x) {
    {
        Connection connection = null;
        PreparedStatement pst = null;
        ResultSet rs = null;
        ArrayList personelList = null;


        try {
            connection = DBFactory.getConnection();
            String sql = 
                    "select  p.adi || ' ' || p.soyadi isim, p.tckimlikno , p.subeno, p.daireno " +
                    "from personel p " +
                    "where p.listedegorunsun = 1 "
                + x
                + "order by nlssort(p.adi||' '||p.soyadi,'NLS_SORT = TURKISH')";

            pst = DBFactory.getPreparedStatement(connection, sql);

            rs = pst.executeQuery();
            personelList = new ArrayList();

            PersonelForm pForm = null;

            while (rs.next()) {

                pForm = new PersonelForm();

                //fill form setter


                personelList.add(pForm);
            }

            return personelList;

        } catch (Exception e) {
            throw new BDException(e.getMessage());
        } finally {
            DBFactory.closeConnection(connection, pst, rs);
        }

    }
}

It's nothing to do with serverside. 与服务器端无关。 It can be done on the client side using javascript or jquery see the following jsfiddle and original post . 可以使用javascript或jquery在客户端完成,请参见以下jsfiddle和原始文章

http://jsfiddle.net/RbLVQ/62/ http://jsfiddle.net/RbLVQ/62/

 $('#btnRight').click(function(e) {
    var selectedOpts = $('#lstBox1 option:selected');
    if (selectedOpts.length == 0) {
        alert("Nothing to move.");
        e.preventDefault();
    }

    $('#lstBox2').append($(selectedOpts).clone());
    $(selectedOpts).remove();
    e.preventDefault();
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM