Unable to use p:dataTable in composite component with some o

UI Components for JSF
Post Reply
User avatar
gturner@unzane.com
Posts: 2
Joined: 01 Nov 2011, 00:44

13 Mar 2013, 21:05

Hello, I have made a simple composite component out of p:dataTable with two goals in mind: hide all the repeated paginiation setup and other sundry attributes into a component rather than be repeated everywhere; store state information (page, filter, etc.) in a bean so position will be restored between page views. This has worked great:

Code: Select all

  <composite:implementation>
    <p:dataTable var="row"
                 value="#{cc.attrs.value}"
                 filteredValue="#{cc.attrs.state.filteredValue}"
                 first="#{cc.attrs.state.first}"
                 paginator="true"
                 paginatorAlwaysVisible="true"
                 paginatorPosition="bottom"
                 paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                 rowsPerPageTemplate="10,20,50,100"
                 currentPageReportTemplate="Record {startRecord} to {endRecord} of {totalRecords}"
                 rows="#{cc.attrs.state.rows}"
                 styleClass="#{cc.attrs.styleClass}"
                 rowStyleClass="#{cc.attrs.rowStyleClass}">
      <f:event type="preRenderComponent" listener="#{cc.attrs.state.onPreRenderComponent}"/>
      <p:ajax event="page" listener="#{cc.attrs.state.onPage}"/>
      <p:ajax event="sort" listener="#{cc.attrs.state.onSort}"/>
      <p:ajax event="filter" listener="#{cc.attrs.state.onFilter}"/>
      <composite:insertChildren/>
    </p:dataTable>
  </composite:implementation>
Problem occurs when I try and add some optional attributes like selectionMode, selection, and rowKey. Pages which don't use these attributes throw an exception:

Code: Select all

  DataModel must implement org.primefaces.model.SelectableDataModel when selection is enabled.
    at org.primefaces.component.datatable.DataTable.getRowKeyFromModel(DataTable.java:922) [primefaces-3.5.jar:]
    at org.primefaces.component.datatable.DataTableRenderer.encodeRow(DataTableRenderer.java:739) [primefaces-3.5.jar:]
Particularly the attribute selectionMode="#{cc.attrs.selectionMode}" evals to empty string, and the code in DataTable does the following:

Code: Select all

  public boolean isRowSelectionEnabled() {
    return this.getSelectionMode() != null;
  }
If DataTable did empty string tests then the optional attributes would be supported, for example:

Code: Select all

  public boolean isRowSelectionEnabled() {
    String mode = getSelectionMode();
    return mode != null && !mode.equals("");
  }
Only work-around besides modifying PrimeFaces that I can think of is of course having a second, redundant composite component where these attributes are required.

I've tried things like selectionMode="#{not empty cc.attrs.selectionMode ? cc.attrs.selectionMode : null}" and still get empty string. Is there any way to coerce EL, cc.attrs, or ComponentStateHelper#eval to return null?
PrimeFaces 3.5; JBossAS 7.1,1.Final; Mojarra 2.1.7-jbossorg-2

wschmitz
Posts: 29
Joined: 13 Dec 2012, 23:50

23 Sep 2014, 17:09

I know this is an old thread, but if it helps someone, here is what we use for "selectionMode":

Code: Select all

<p:dataTable....>
        <c:if test="${not empty cc.attrs.selectionMode}">
                <f:attribute name="selectionMode" value="#{cc.attrs.selectionMode}"/>
         </c:if>
</p:dataTable>
The ones we don't have a work around for are attributes that are Array or Collection types, e.g. "selection" and "filteredValue". The above does not work in these scenarios.
Using Primefaces 5.0.9, Primefaces Ext 2.1.0, MyFaces JSF 2.2.0, Tomcat 7.0.54

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 48 guests