I'm trying to avoid code duplication by putting the content of my table headers (~100) into a composite component. This works fine for most of the things I want to show there (Headline, Row count, Selected rows count, Select all/none-Buttons etc.).
Now I'm trying to use a p:columnToggler to allow the users to hide columns. The problem is: The ID of the p:dataTable obviously can't be resolved for the "datasource" attribute as soon as the columnToggler is within my composite header component (vat:tableHeader).
Here the (extracted) code of my page:
Code: Select all
<p:dataTable id="myTable" var="line" value="#{list}">
<f:facet name="header">
<vat:tableheader showColumnToggler="true" />
</f:facet>
<p:column
headerText="#{msg['header.countries']}"
<h:commandLink
action="#{myController.openDetailRecord(line)}"
value="#{line.label}" />
</p:column>
...
And this is the component (also shortened and hard coded the table ID as a data source to avoid possible problems with cc.attrs; also used ":myTable" and "myTable" instead of "myForm:myTable"):
Code: Select all
...
<composite:interface>
<composite:attribute name="showColumnToggler" default="false"
type="java.lang.Boolean" required="false" />
</composite:interface>
<composite:implementation>
<p:layout style="min-height:2em" rendered="#{not empty cc.attrs.list}">
< ... other content omitted ... />
<p:layoutUnit position="east" size="150" rendered="#{cc.attrs.showColumnToggler}">
<p:commandButton id="toggler" type="button" value="Columns"
style="float:right" icon="ui-icon-calculator" />
<p:columnToggler datasource="myForm:myTable" trigger="toggler">
<p:ajax event="toggle" />
</p:columnToggler>
</p:layoutUnit>
</p:layout>
</composite:implementation>
Code: Select all
javax.servlet.ServletException: Cannot find component with expression "myForm:myTable" referenced from "myTable:j_idt140:j_idt149".
javax.faces.webapp.FacesServlet.service(FacesServlet.java:659)
io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)
...
I already used some other techniques to get the correct ID, so I think that's not the problem.
Thanks in advance!