Columns as facet to datatable composite component

UI Components for JSF
Post Reply
javarab
Posts: 1
Joined: 27 Jun 2011, 17:05

27 Jun 2011, 17:30

Hello all,

This is my first post on these forums. I'd like to thank everyone for the questions and answers already on these forums, they helped me immensely getting started with primefaces. However, I have run into a problem that I cannot solve on my own, I am hoping someone can help me.

Basically, I am trying to create a simple component based around a <p:datatable>. The idea is that I have a datatable that has a Show More / Show Less toggle link at the top of the table. The default position is showMore, and display only the first 2 rows of the table, with no table header facets, and no pagination. When the Show More link is clicked, I want to show the full table, with header facets and pagination. The way I was planning to implement the component, was to define two facets that the implementing page would prepare and pass in. There would be one facet for 'showMore' columns, and another for 'showLess' columns. They would effectively be the same thing, except that the showLess column would not provide any header facets for the columns.

The problem I am seeing is that no columns are being rendered in my table, however, the pagination works and I can see the correct number of pagainatino pages for the data being passed in. So, I think the problem is with the facets I am passing in. Without further ado, the code I have creates is shown below.

Primefaces: 2.2.1
Mojarra:2.0.3
Tomcat 7.0
JDK 1.6

Component

Code: Select all

<?xml version="1.0" encoding="utf-8"?>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:c="http://java.sun.com/jsp/jstl/core"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.prime.com.tr/ui"
      xmlns:cc="http://java.sun.com/jsf/composite">
	<cc:interface>	
		<cc:attribute name="widgetVar" />
		<cc:attribute name="var" />
		<cc:attribute name="controller" type="com.mypackage.controller.GenericDatatableController" />		
		<cc:attribute name="emptyMessage" />
		<cc:attribute name="moreRows" default="5"/>
		<cc:attribute name="lessRows" default="2"/>
		<cc:facet name="header" required="true"/>
		<cc:facet name="showMore" required="true"/>
		<cc:facet name="showLess" required="true"/>
	</cc:interface>
	<cc:implementation>				
		<h3><cc:renderFacet name="header"/></h3>	
		<h:form>		 
			<p:commandLink update="searchTabs growl" value="#{msg['views.client.showmore']}" actionListener="#{cc.attrs.controller.toggleShowMore}" rendered="#{not cc.attrs.controller.showMore}"/>
			<p:commandLink update="searchTabs growl" value="#{msg['views.client.showless']}" actionListener="#{cc.attrs.controller.toggleShowMore}" rendered="{cc.attrs.controller.showMore}"/>			
			<p:dataTable widgetVar="showMore"
			                         value="#{cc.attrs.controller.data}"
						 selection="#{cc.attrs.controller.selected}"
						 rowSelectListener="#{cc.attrs.controller.onSelection}"						 							
						 onRowSelectUpdate="searchTabs growl"
						 paginator="true" 
						 rendered="#{cc.attrs.controller.showMore}"
						 rows="#{cc.attrs.moreRows}" 
						 paginatorAlwaysVisible="false"	
						 emptyMessage="#{cc.attrs.emptyMessage}"			 
						 selectionMode="single"> 
				<c:set target="#{component}" property="var" value="#{cc.attrs.var}"/>
				<cc:renderFacet name="showMore" />
			</p:dataTable>
			<p:dataTable widgetVar="showLess"
			             value="#{cc.attrs.controller.data}"
						 selection="#{cc.attrs.controller.selected}"
						 rowSelectListener="#{cc.attrs.controller.onSelection}"						 							
						 onRowSelectUpdate="searchTabs growl"
						 paginator="false" 
						 rendered="#{not cc.attrs.controller.showMore}"
						 rows="#{cc.attrs.lessRows}" 
						 paginatorAlwaysVisible="false"	
						 emptyMessage="#{cc.attrs.emptyMessage}"			 
						 selectionMode="single">
				<c:set target="#{component}" property="var" value="#{cc.attrs.var}"/>
				<cc:renderFacet name="showLess" />																
			</p:dataTable>					
		</h:form>
	</cc:implementation>
</html>
And the page using the component is as below:

Code: Select all

<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
				xmlns:ui="http://java.sun.com/jsf/facelets"
				xmlns:h="http://java.sun.com/jsf/html"
				xmlns:f="http://java.sun.com/jsf/core"
				xmlns:c="http://java.sun.com/jsp/jstl/core"
				xmlns:cc="http://java.sun.com/jsf/composite"
				xmlns:dt="http://java.sun.com/jsf/composite/components/datatable"
				xmlns:p="http://primefaces.prime.com.tr/ui">				
	<dt:showMore var="row"
			      widgetVar="MyDataTable"
			      controller="#{searchController}"
	                      emptyMessage="#{msg['datatable.empty']}">
		<f:facet name="header">Show More / Less Table</f:facet>
		<f:facet name="showMore">
			<p:column>
				<f:facet name="header">
					<h:outputText value="#{msg['header.name']}" />
				</f:facet>
				<h:outputText value="#{row.name}" />
			</p:column>
			<p:column>
				<f:facet name="header">
					<h:outputText value="#{msg['header.role']}" />
				</f:facet>
				<h:outputText value="#{row.role}" />
			</p:column>
		</f:facet>
		<f:facet name="showLess">
			<p:column>
				<h:outputText value="#{row.name}" />
			</p:column>
			<p:column>
				<h:outputText value="#{row.role}" />
			</p:column>
		</f:facet>			
	</dt:showMore>
</ui:composition>
Any help / pointers in accomplishing my goal of passing in the facets would be greatly appreciated. Or if you have any alternative design strategies for achieving the show more / show less feature.

Many thanks,
JR

lmmoreira
Posts: 60
Joined: 08 Jul 2010, 14:15

16 Jul 2011, 16:38

Hi friend did you managed to do this, or find another way?

Thanks a lot
Tomcat 7 + jsf-api - 2.0.3-SNAPSHOT + Primefaces 2.1

funkybreizh
Posts: 5
Joined: 23 Aug 2011, 16:00

25 Aug 2011, 11:36

Hi,

I'm working on the same problem, did you find a solution?

Thanks
Mojara 2.12
Primefaces 3.0.M3

lenik
Posts: 3
Joined: 31 Jan 2012, 16:26

31 Jan 2012, 18:08

I have the same problem, too. Well, I have changed to use cc:insertChildren instead.

See also: http://lists.jboss.org/pipermail/jsr-31 ... 01526.html

Hamsterbau
Posts: 409
Joined: 28 Dec 2011, 17:44

31 Jan 2012, 18:19

Perhaps i misunterstand what you really want, but in my opinion all you have to do is implement one datatable and higher the "rows" attribute to your needs? So the "showMore" button can just add more rows to your rendered table (with an update on that table after set "rows" to a higher value.
Primefaces 8.0.7 (PF Extensions 8.0)
JSF: Mojarra 2.3.2 (Spec 2.3) - running on WildFly 22

lenik
Posts: 3
Joined: 31 Jan 2012, 16:26

01 Feb 2012, 07:47

I've created my own tag handler <insertRawFacet> to overcome this problem.

See http://stackoverflow.com/questions/7891 ... 13#9091313.

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 58 guests