简体   繁体   中英

how to add value listbox with another listbox java struts?

i want to use two listbox (multiple) on java struts enviroment. 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.

my code is:

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 .

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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