2013-03-01 34 views
1

我想在java struts環境中使用兩個listbox(多個)。第一個列表框列出了個人名稱,第二個列表框空白。使用添加和刪除按鈕,從第一個列表框中填充第二個列表框。但我不知道如何使用它?如何添加值列表框與另一個列表框java struts?

值是字符串數組還是集合到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); 
     } 

    } 
} 

回答

0

這是無關的服務器端。它可以在客戶端使用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(); 
}); 
+0

我可以說沒有問題。我的問題在於struts。 – 2013-03-01 13:33:01

相關問題