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>
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>
Many thanks,
JR