问题描述
我有一个primefaces数据表,其中包含许多类似的列,例如
I have a primefaces datatable with a lot of similar columns such as
<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>
有没有一种方法可以为其创建复合材料,例如编写
Is there a way of creating a composite for it such as to write
<mine:column value="#{element.value}" header="Some header" headerTooltip="Some header tooltip" />
我已经搜索/尝试了一天,但没有任何真正的成功.我设法将< ui:include ...>
与params一起使用,但是它几乎和原始版本一样冗长
I've been searching/trying things for a day now without any real success.I've managed to use an <ui:include...>
with params but it's almost as verbose as the original
<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 ,即使它使用richfaces和此解决方案列为DataTable中的复合组件,但没有任何作用.
I've tried using taglib as preconized here How to create a composite component for a datatable column? even if it uses richfaces and this solution Column as Composite Component inside DataTable but none work.
我还在某处读到< p:column ...>
应该是< p:datatable ...>
的直接子代因此这是不可能的,但我相信那是旧的Primefaces版本(3或4).
I've also read somewhere that <p:column...>
should be a direct child of <p:datatable...>
so it is not possible but I believe that was with old primefaces version (3 or 4).
那么,有谁知道Primefaces 6或8是否可行,怎么办?
So, does anyone know if it is possible with Primefaces 6 or 8 and if so how?
推荐答案
您可以使用以干燥您的代码.
You can use custom Facelet tags to DRY your code.
只需为以下列创建标签:
Simply create tags for columns like:
<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>
这是我们的项目之一中的表格外观:
This is how a table looks in one of our projects:
<dt:dataTable controller="#{controller}"
sortField="activationDate">
<dt:column id="id"/>
<dt:columnDate id="activationDate"/>
...
<dt:dataTable/>
这篇关于如何将Primeface列包含在组合中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!