我正在使用p:datatable
and selection 在我的 bean 中处理选定的记录。这行得通。但是我想在初始化数据表时预设一个选定的行。这可能吗?如何?
现在它不会预设记录,即使已设置 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}"/>