2011-06-15 36 views
1

我想請教一下在列表框中從多個選擇中獲得價值,我已經在ZUL代碼:充分利用多選擇在列表框中ZK值

<n:tr> 
       <n:td> 
        <label value="Privilege"/> 
       </n:td> 
       <n:td> 
        <label value=""/> 
       </n:td> 
       <n:td> 
        <listbox id="designations" model="@{addUser$composer.lstPrivilege}" selectedItem="@{selectedUserAcc, converter=com.nsia.doku.escrow.converter.SelectedItemConverter}" multiple="true" checkmark="true" width="200px"> 
           <listitem self="@{each=lstPrivilege}" > 
            <listcell label="@{lstPrivilege.description}"/> 
           </listitem> 
        </listbox> 
       </n:td> 
      </n:tr> 
      <n:tr> 
       <n:td> 

       </n:td> 
       <n:td> 

       </n:td> 
       <n:td> 
        <button label="Submit" onClick=' 
        import com.dokuescrow.dto.Activity; 
        ArrayList al = new ArrayList(); 
         for (Activity li : selectedUserAcc) 
         { 
          al.add(li.activityId); 
         } 
         alert(al); 
        '/> 
       </n:td> 
      </n:tr> 

我的問題是,我如何得到選擇的值在我的控制器類中,我測試我的按鈕使用onClick='..,值selectedUserAcc不爲空,就像我想要的,如果我在我的控制器類(例如使用方法)傳遞動作,我打印出的值爲null ..任何人想幫助我,我的班級出了什麼問題?

我在控制器的方法是這樣的:

public void onClick$submit(Event event){ 
     try { 

      ArrayList al = new ArrayList(); 
         for (Activity li : selectedUserAcc) 
         { 
          al.add(li.getActivityId()); 
         } 
      alert(al.toString()); 
     } catch (Exception e) { 
      e.printStackTrace(); 
     } 

    } 

希望有人能幫助me..thanks ..:d

回答

2

OK,谷歌搜索,搜索和嘗試後(:d),我得到了這個問題的答案,你必須做的事情是在你的控制器中調用轉換器,我從ZK論壇here 得到的轉換器,並將返回更改爲對象,(bot返回null),我的代碼將如下所示:

SelectedItemConverter select=new SelectedItemConverter(); 

     for (Activity li : (Set<Activity>)select.coerceToBean(selectedUserAcc, getListGent())) 
         { 
          al.add(li); 
         } 


         List<Activity> act=al; 

,所以我有我選擇的對象我want..thanks的關注..:d

litGen是我lisbox ID