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

时间:2013-03-01 09:01:07

标签: java javascript jquery listbox struts

我想在java struts环境中使用两个listbox(multiple)。第一个列表框是列出的个人名称,第二个列表框首先是空白。使用添加和删除按钮,使用所选第一个列表框中的值填充第二个列表框。但我不知道如何使用它?

value是字符串数组还是getter / setter的集合?以及如何使用?

此外,我知道javascript代码如何制作但struts很复杂。

我的代码是:

JSP:

  

第一个列表框和第二个列表框

< 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>
  

我的表单代码是

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

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

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

模型类

  
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);
        }

    }
}

1 个答案:

答案 0 :(得分:0)

这与serverside无关。它可以使用javascript或jquery在客户端完成 请参阅以下jsfiddle和original post

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();
});