PrimeFaces 14中DataTable的rowsPerPageLabel属性不显示问题咨询
PrimeFaces 14中
<p:dataTable> 的 rowsPerPageLabel 属性问题解答 问题描述
将PrimeFaces从13版本升级至14版本后,<p:dataTable> 组件的 rowsPerPageLabel 属性设置后,分页器下拉框的标签文本不再显示。尝试通过 paginatorTemplate 直接添加标签文本,但显示效果不理想;而在13及更早版本中,通过该属性设置的标签显示正常。测试用最小代码示例如下:
<p:dataTable value="#{testTableData.testLandliste}" var="item" paginator="true" rows="10" rowsPerPageTemplate="5,10,20" rowsPerPageLabel="Rows per page:" paginatorPosition="bottom" paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}" currentPageReportTemplate="{startRecord}-{endRecord} of {totalRecords} records"> <p:column headerText="Name"> <h:outputText value="#{item.nameEnglisch}" /> </p:column> </p:dataTable>
问题原因与解决方案
rowsPerPageLabel 属性并未被弃用,但PrimeFaces 14对分页器的渲染逻辑做了调整:在13及更早版本中,rowsPerPageLabel 的文本会自动附加到 {RowsPerPageDropdown} 元素前;而在14版本中,必须在 paginatorTemplate 中显式添加 {RowsPerPageLabel} 占位符,才能让设置的标签文本正常显示。
修改后的 paginatorTemplate 配置如下:
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageLabel} {RowsPerPageDropdown}"
添加 {RowsPerPageLabel} 占位符后,rowsPerPageLabel 属性设置的文本就会正确显示在分页下拉框前方,效果与13版本一致。
内容的提问来源于stack exchange,提问作者K Akhil
相关产品推荐
相关产品推荐

