p:columnToggler can't find datasource if in a composite comp

UI Components for JSF
Post Reply
RalfWohner
Posts: 7
Joined: 29 Jan 2016, 16:11

02 Feb 2016, 12:01

Hi there,

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>
The result is:

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)
...
Can anyone help or show me a workaround / alternative?

I already used some other techniques to get the correct ID, so I think that's not the problem.

Thanks in advance!
Using PrimeFaces 5.1 (Extensions 2.0.0) / JBoss-JSF-API 2.2 on a Wildfly 8.1.0
Client Browsers range from IE10 to anything modern

RalfWohner
Posts: 7
Joined: 29 Jan 2016, 16:11

02 Feb 2016, 15:27

Oh my... I think I found it...

the datasource ID was missing a ":" in the beginning:

Correct:

Code: Select all

datasource=":myForm:myTable"
Obviously I didn't really understand JSF-references... Sorry. Hope this helps someone.
Using PrimeFaces 5.1 (Extensions 2.0.0) / JBoss-JSF-API 2.2 on a Wildfly 8.1.0
Client Browsers range from IE10 to anything modern

kukeltje
Expert Member
Posts: 9605
Joined: 17 Jun 2010, 13:34
Location: Netherlands

02 Feb 2016, 20:59

You seriously have a full layout in a composite component? ok... never seen that

RalfWohner
Posts: 7
Joined: 29 Jan 2016, 16:11

03 Feb 2016, 10:17

kukeltje wrote:You seriously have a full layout in a composite component? ok... never seen that
:) Why not? Our customers want all the information in their table headers. After fixing my error, everything works fine there, now.
Using PrimeFaces 5.1 (Extensions 2.0.0) / JBoss-JSF-API 2.2 on a Wildfly 8.1.0
Client Browsers range from IE10 to anything modern

kukeltje
Expert Member
Posts: 9605
Joined: 17 Jun 2010, 13:34
Location: Netherlands

03 Feb 2016, 10:48

I normally do layout in the header of a datatable with plain divs, not a layout component (never had the request to being able to size, open, close etc in a header). Thats all, hence the surprise

RalfWohner
Posts: 7
Joined: 29 Jan 2016, 16:11

03 Feb 2016, 15:10

Ah, OK. Well, I don't use sizing / closing etc. there as well, I just wanted to stay "in the framework" - and when it's rendered they become quite normal divs anyway.
Using PrimeFaces 5.1 (Extensions 2.0.0) / JBoss-JSF-API 2.2 on a Wildfly 8.1.0
Client Browsers range from IE10 to anything modern

kukeltje
Expert Member
Posts: 9605
Joined: 17 Jun 2010, 13:34
Location: Netherlands

03 Feb 2016, 18:37

plain html divs are 'in the framework' to... :D I only use jsf components when plain html is not sufficient... Just a choice...

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 12 guests