Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>To resolve your problem, you need to use the <code>rich:dataTable</code> and <code>rich:subTable</code>. There is an example in the <a href="http://livedemo.exadel.com/richfaces-demo/richfaces/dataTable.jsf?c=dataTable&amp;tab=usage" rel="nofollow">exadel live demo</a> site.</p> <p>Let's have a look in the code (this is not the real code of the site, it's just an example to get the idea):</p> <p>Java Classes</p> <pre><code>//POJOs public class Expenses { private Date day; private decimal meals; private decimal hotels; private decimal transports; //getters and setters for the attributes; } public class Record { private String city; private List&lt;Expenses&gt; items; private decimal totalMeals; private decimal totalHotels; private decimal totalTransport; private decimal total; //getters and setters for the attributes; } public class ExpReport { private List&lt;Record&gt; records; private decimal totalMeals; private decimal totalHotels; private decimal totalTransport; private decimal grandTotal; //getters and setters for the attributes; } //Managed Bean public class Report { private ExpReport expReport; //getter and setter for the attribute; } </code></pre> <p>We have the managed bean Report that contains an instance of ExpReport. Inside ExpReport we have a List of Records (the list we want to display in the table), but each record has its own inner List of Expenses (the list we want to display along with the records). Now, we just need to set up our rich:dataTable and the rich:subTable in it to get the magic flowing in our jsp.</p> <p>Note: You can get more info on the documentation of <a href="http://docs.jboss.org/richfaces/latest_3_3_X/en/devguide/html/rich_column.html" rel="nofollow">rich:column</a>.</p> <pre><code>&lt;!-- Here we set the data list for the dataTable as the list of records of our object expReport. Also, the name of the iterator will be 'record' --&gt; &lt;rich:dataTable width="100%" value="#{report.expReport.records}" var="record"&gt; &lt;f:facet name="header"&gt; &lt;!-- This columnGroup tag component will define a group of columns for the header of the dataTable (the body of the dataTable can has more columns, for this example there will be the same).--&gt; &lt;rich:columnGroup&gt; &lt;rich:column rowspan="2"&gt; &lt;rich:spacer /&gt; &lt;/rich:column&gt; &lt;rich:column colspan="3"&gt; &lt;h:outputText value="Expenses" /&gt; &lt;/rich:column&gt; &lt;rich:column rowspan="2"&gt; &lt;h:outputText value="subtotals" /&gt; &lt;/rich:column&gt; &lt;!-- The 'breakBefore' attribute tells the column to start from the next row to be rendered in the dataTable. This attribute doesn't affect the rows generated in rich:extendedDataTable. For more info, see the documentation (link above the code). --&gt; &lt;rich:column breakBefore="true"&gt; &lt;h:outputText value="Meals" /&gt; &lt;/rich:column&gt; &lt;rich:column&gt; &lt;h:outputText value="Hotels" /&gt; &lt;/rich:column&gt; &lt;rich:column&gt; &lt;h:outputText value="Transport" /&gt; &lt;/rich:column&gt; &lt;/rich:columnGroup&gt; &lt;/f:facet&gt; &lt;!-- Now, let's set the content of the rows of the dataTable --&gt; &lt;!-- This column will show city from our 'record' iterator. --&gt; &lt;rich:column colspan="5"&gt; &lt;h:outputText value="#{record.city}" /&gt; &lt;/rich:column&gt; &lt;!-- After printing the city, we want to show the data from the expenses made in this record. For this, we will use the subTable tag component, setting the 'record.items' list as the data list for subTable and naming the inner iterator 'expense'. The syntax for the subTable is like the dataTable. --&gt; &lt;rich:subTable value="#{record.items}" var="expense"&gt; &lt;rich:column&gt; &lt;h:outputText value="#{expense.day}" /&gt; &lt;/rich:column&gt; &lt;rich:column&gt; &lt;h:outputText value="#{expense.meals}"&gt; &lt;f:convertNumber pattern="$####.00" /&gt; &lt;/h:outputText&gt; &lt;/rich:column&gt; &lt;rich:column&gt; &lt;h:outputText value="#{expense.hotels}"&gt; &lt;f:convertNumber pattern="$####.00" /&gt; &lt;/h:outputText&gt; &lt;/rich:column&gt; &lt;rich:column&gt; &lt;h:outputText value="#{expense.transport}"&gt; &lt;f:convertNumber pattern="$####.00" /&gt; &lt;/h:outputText&gt; &lt;/rich:column&gt; &lt;rich:column&gt; &lt;rich:spacer /&gt; &lt;/rich:column&gt; &lt;/rich:subTable&gt; &lt;/rich:dataTable&gt; </code></pre> <p>Sorry for my bad english, I hope this can be helpful in your application.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload