我有一个 primefaces 数据表,其中有很多类似的列,例如
<p:column filterBy="#{element.value}" filterFunction="#{applicationHelperController.filterByNumber}" styleClass="ps-90-header" >
<f:facet name="header">
<p:tooltip for="@next" value="Some header tooltip"/>
<h:outputText id="#{header}_id" value="Some header" styleClass="ps-90-header" />
</f:facet>
<h:outputText value="#{element.value}" />
</p:column>
有没有办法为其创建一个组合,例如编写
<mine:column value="#{element.value}" header="Some header" headerTooltip="Some header tooltip" />
我已经搜索/尝试了一天,但没有取得任何真正的成功。
我已经设法使用 <ui:include...>
带有参数,但它几乎和原来一样冗长
<ui:include src="/WEB-INF/includes/countColumn.xhtml" >
<ui:param name="value" value="#{element.value}"/>
<ui:param name="header" value="Some header"/>
<ui:param name="headerTooltip" value="Some header tooltip"/>
</ui:include>
我尝试使用 taglib 作为预定义,这里 How to create a composite component for a datatable column?即使它使用 richfaces 和此解决方案 Column as Composite Component inside DataTable但没有任何效果。
我还在某处读过<p:column...>
应该是 <p:datatable...>
的直接子代所以这是不可能的,但我相信这是旧的 primefaces 版本(3 或 4)。
那么,有谁知道 Primefaces 6 或 8 是否可以实现这一点?如果可以,如何实现?
最佳答案
您可以使用custom Facelet tags干燥您的代码。
只需为列创建标签,例如:
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<p:column ...>
...
</p:column>
</ui:composition>
这是我们的一个项目中表格的外观:
<dt:dataTable controller="#{controller}"
sortField="activationDate">
<dt:column id="id"/>
<dt:columnDate id="activationDate"/>
...
<dt:dataTable/>
关于jsf - 如何将 primeface 列包含到复合 Material 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66674245/