Book Image

Primefaces Cookbook Second Edition

Book Image

Primefaces Cookbook Second Edition

Overview of this book

Table of Contents (20 chapters)
PrimeFaces Cookbook Second Edition
Credits
Foreword
Foreword
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Using subTable for grouping


A helper component, subTable can be used to group row data inside a table.

How to do it…

A basic definition of a table that contains subTable is given here:

<p:dataTable value="#{dataTableBean.boxers}" var="boxer">
  <f:facet name="header">
    Boxers
  </f:facet>

  <p:columnGroup type="header">
    <p:row>
      <p:column rowspan="2" headerText="Boxer" />
      <p:column colspan="2" headerText="Stats" />
    </p:row>
    <p:row>
      <p:column headerText="Wins" />
      <p:column headerText="Losses" />
    </p:row>
  </p:columnGroup>

  <p:subTable var="stats" value="#{boxer.stats}">
    <f:facet name="header">
      <h:outputText value="#{boxer.name}" />
    </f:facet>
    <p:column>
      <h:outputText value="#{stats.match}" />
    </p:column>
    <p:column>
      <h:outputText value="#{stats.win}" />
    </p:column>
    ...