Primefaces 动态列不适用于延迟加载
Posted
技术标签:
【中文标题】Primefaces 动态列不适用于延迟加载【英文标题】:Primefaces Dynamic columns not working with lazy loading 【发布时间】:2014-12-20 13:47:14 【问题描述】:我正在使用 PF 5.0、JSF 2.0 (Mojarra)、Spring Webflow 2.3。我在使用 Datatable 延迟加载时遇到了多个问题。
a.) 当我尝试为 DataTable 组件使用惰性数据模型的列进行多选时,当我为 Data table 启用单选时,它工作正常。 b.) 我在使用 Datatable 时遇到的另一个问题是我无法使用 Lazy Data table 加载动态列,它曾经在非 Lazy 版本中运行良好。
欢迎提出解决这些问题的任何建议。请在下面找到代码。
<p:dataTable id="docsTable" var="document"
value="#datasource" lazy="true" paginator="true" dynamic="true"
rows="#searchActionBean.maxRows" paginatorTemplate="FirstPageLink PreviousPageLink PageLinks NextPageLink LastPageLink RowsPerPageDropdown"
rowsPerPageTemplate="10,25,50,100" rowKey="#document.ID"
sortMode="single" resizableColumns="true" scrollable="true" scrollHeight="350" >
<f:facet name="header">
<p:toolbar>
<f:facet name="left">
<p:commandButton type="button" title="Print" icon="ui-icon-print" />
<span class="ui-separator">
<span class="ui-icon ui-icon-grip-dotted-vertical" />
</span>
<p:commandButton id="reptoggler" value="Reports" action="reportsAction" icon="ui-icon-note">
<f:param name="stdReportName" value="reportsMain" />
</p:commandButton>
</f:facet>
<f:facet name="right">
<h:outputText value="#searchActionBean.domainName" />(<h:outputText value="#searchActionBean.resultCount" />)
<span class="ui-separator">
<span class="ui-icon ui-icon-grip-dotted-vertical" />
</span>
<h:commandLink>
<img src="$request.contextPath/images/excel.png" />
<p:dataExporter type="xls" target="docsTable" fileName="documents" />
</h:commandLink>
<span class="ui-separator">
<span class="ui-icon ui-icon-grip-dotted-vertical" />
</span>
<h:commandLink>
<img src="$request.contextPath/images/pdf.png" />
<p:dataExporter type="pdf" target="docsTable" fileName="documents" />
</h:commandLink>
<span class="ui-separator">
<span class="ui-icon ui-icon-grip-dotted-vertical" />
</span>
<p:commandButton id="toggler" type="button" value="Columns" icon="ui-icon-calculator" />
<p:columnToggler datasource="docsTable" trigger="toggler" />
</f:facet>
</p:toolbar>
</f:facet>
<p:column selectionMode="multiple" style="text-align:center; width:25px">
<f:facet name="header">
<h:outputText value="Select" />
</f:facet>
</p:column>
<p:columns value="#searchResultsColumns" var="column" styleClass="wrap" columnIndexVar="colIndex" sortBy="#document[column.pfResColumnName]" filterBy="#document[column.pfResColumnName]">
<f:facet name="header">
<h:outputText value="#column.displayResultColumnName" />
</f:facet>
<h:outputText value="#document[column.pfResColumnName]" rendered="#column.resColumnType eq 'DATE'">
<f:convertDateTime pattern="MM/dd/yyyy" />
</h:outputText>
<h:outputText value="#document[column.pfResColumnName]" rendered="#column.resColumnType eq null" />
<h:outputText value="#document[column.pfResColumnName]" rendered="#column.resColumnType eq 'SPL'">
<f:converter converterId="gov.nih.nci.ctep.idart.converters.SplConverter"></f:converter>
</h:outputText>
</p:columns>
</p:dataTable>
还有 Bean 代码,我已经验证 Collections searchResultColumns 不为空。
public class SearchActionBean extends LazyDataModel<DocumentResultDTO> implements Serializable
private List<DocumentResultDTO> datasource;
@Override
public DocumentResultDTO getRowData(String rowKey)
for (DocumentResultDTO doc : datasource)
if (doc.getID().equals(rowKey))
return doc;
return null;
@Override
public Object getRowKey(DocumentResultDTO doc)
return doc.getID();
@Override
public List<DocumentResultDTO> load(int first, int pageSize, String sortField,
SortOrder sortOrder, Map<String, Object> filters)
datasource = new ArrayList<DocumentResultDTO>();
/*this.execute();*/
commonQueriesLocal = ejbService.getCommonQueriesLocal();
srchDelegate = new SearchDelegate();
super.setSearchDelegate(srchDelegate);
try
//Set the visibility of all the columns depending on the JQuery table visibility setting from the client side
String invisibleColNames = request.getParameter("invisibleColNames");
ArrayList<UserResultColumnDTO> dispCols = getDisplayColumns();
ApplicationUtils.markVisibilityForColumns(dispCols,invisibleColNames);
int iSortColumnIndex = 1;
String sSortDirection = sortOrder.toString().equalsIgnoreCase("ASCENDING") ? "asc" : "desc";
if(request.getParameter("iSortCol_0") != null)
iSortColumnIndex = Integer.parseInt(request.getParameter("iSortCol_0"));
Query query =
(Query) request.getSession().getAttribute(IdartWebGlobalConstants.USER_QUERY);
if(request.getSession().getAttribute("executeSavedQuery") != null &&
request.getSession().getAttribute("executeSavedQuery").toString().equalsIgnoreCase("true")
)
pageSize = query.getUserQuery().getPageCount();
else
query.getUserQuery().setPageCount(pageSize);
query.getUserQuery().setSortOrder(sSortDirection);
setDataSortColumn(iSortColumnIndex, getDomainNameToSetSortColumn(query.getName()), query);
performNavigation(pageSize, first);
// Save the query object in session
if(getDomainName().equalsIgnoreCase("DOCUMENTS"))
setSearchResults((ArrayList)request.getAttribute("documentResults"));
setSearchResultsColumns(dispCols);
System.out.println("search Result "+searchResults.size());
System.out.println("search Columns "+dispCols.size());
// process on filters to be displayed
customizeFilterResults();
catch(Exception ex)
log.error("-- GetData Method Error "
+ ex.getMessage()
+ " --", ex);
datasource= getSearchResults();
System.out.println("first "+first+" pageSize "+pageSize+" sortField "+sortField+" sortOrder "+sortOrder);
System.out.println("searchResultsColumns"+datasource);
System.out.println("searchResultsColumns "+searchResultsColumns);
System.out.println("GET searchResultsColumns "+getSearchResultsColumns());
// rowCount
int dataSize = datasource.size();
this.setRowCount(Integer.parseInt(getResultCount()));
return datasource;
【问题讨论】:
【参考方案1】:查看控制台,看看是否有任何错误。 PrimeFaces (2.0) 早期版本中的延迟加载似乎破坏了某些 PrimeFaces 工具(如 ToolTips)。
我能够通过在加载延迟加载部分(即在延迟加载
<script src='$request.contextPath/components/jquery/jquery-ui.js'></script>
【讨论】:
以上是关于Primefaces 动态列不适用于延迟加载的主要内容,如果未能解决你的问题,请参考以下文章
休眠延迟加载不适用于 Spring Boot => 无法延迟初始化角色集合无法初始化代理 - 无会话
延迟加载和解析 PrimeFaces JavaScript 文件
Angular <custom-component> 不适用于延迟加载的模块