2012-10-05 60 views
0

我正在使用p:datatable和選擇在我的bean中處理選定的記錄。這工作。但是我想在初始化數據表時預設一個選定的行。這可能嗎?怎麼樣?「p:datatable」選擇

即使設置了selectedCompany,它也不會預設記錄。是否因爲我在回到jsf之前做了這件事?

這是我的代碼有

public Map<String, Object> getSelectedCompany() { 
    return selectedCompany; 
} 

public void setSelectedCompany(Map<String, Object> selectedCompany) { 
    this.selectedCompany = selectedCompany; 
} 
public MWSGenericMapList getHandlingCompanies() { 

    if (companyItems == null) { 
companyItems = retrieveHandlingCompanyItems(partnerIds); 
      for (int i = 0; i < companyItems.size(); i++) { 
       if (companyItems.get(i).get("businesspartnerid").equals(getnewCustomerPartnerId())) { 
        setSelectedCompany(companyItems.get(i)); 
       } 
      } 
} 
return companyItems; 
} 

JSF

<p:dataTable styleClass="ptable100" id="handlingCompanies" var="company" value="#{switchCompany.handlingCompanies}" width="100%" height="200" 
     emptyMessage="#{msg.all_lists_no_records_found}" paginator="true" rows="10" rowsPerPageTemplate="5,10,20,50,100" 
     paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} #{msg.all_lists_numberOfRowsDisplayed_label} {RowsPerPageDropdown}" 
     selection="#{switchCompany.selectedCompany}" selectionMode="single" rowKey="#{company.businesspartnerid}"> 
      <p:ajax event="rowSelect" update="@form" listener="#{switchCompany.handleCompanyChange}"/> 

回答

0

沒關係,所選行沒有得到設置,我只是沒有在第一頁(太多行顯示在1頁),所以我錯過了。但是,它的工作方式與我一樣。