JBoss.orgCommunity Documentation
The <rich:columns> is a component, that allows you to create a dynamic set of columns from your model.
Highly customizable look and feel
Dynamic tables creation
Possibility to combine columns with the help of "colspan" and "breakBefore"
Possibility to combine rows with the help of "rowspan"
The <rich:columns> component gets a list from data model and outputs a corresponding set of columns inside <rich:dataTable> on a page. It is possible to use "header" and "footer" facets with <rich:columns> component.
The "value" and "var" attributes are used to access the values of collection.
The simple example is placed below.
Example:
...
<rich:dataTable value="#{dataTableScrollerBean.model}" var="model" width="750">
<rich:columns value="#{dataTableScrollerBean.columns}" var="columns"
index="ind" id="column#{ind}">
<f:facet name="header">
<h:outputText value="#{columns.header}" />
</f:facet>
<h:outputText value="#{model[ind].model} " />
<h:outputText value="#{model[ind].mileage} miles " />
<h:outputText value="#{model[ind].price}$" />
</rich:columns>
</rich:dataTable>
...
The "columns" attribute defines the count of columns.
The "rowspan" attribute defines the number of rows to be displayed. If the value of this attribute is zero, all remaining rows in the table are displayed on a page.
The "begin" attribute contains the first iteration item. Note, that iteration begins from zero.
The "end" attribute contains the last iteration item.
With the help of the attributes described above you can customize the output, i.e. define which columns and how many rows appear on a page.
The <rich:columns> component does not prevent to use <rich:column> . In the following example one column renders in any way and another columns are picked from the model.
Example:
...
<rich:dataTable value="#{dataTableScrollerBean.model}" var="model" width="500px" rows="5">
<f:facet name="header">
<h:outputText value="Cars Available"></h:outputText>
</f:facet>
<rich:columns value="#{dataTableScrollerBean.columns}" var="columns" index="ind">
<f:facet name="header">
<h:outputText value="#{columns.header}" />
</f:facet>
<h:outputText value="#{model[ind].model} " />
</rich:columns>
<rich:column>
<f:facet name="header">
<h:outputText value="Price" />
</f:facet>
<h:outputText value="Price" />
</rich:column>
<rich:columns value="#{dataTableScrollerBean.columns}" var="columns" index="ind">
<f:facet name="header">
<h:outputText value="#{columns.header}" />
</f:facet>
<h:outputText value="#{model[ind].mileage}$" />
</rich:columns>
</rich:dataTable>
...
The grouping some columns into one column or one row with the help of the "colspan", "rowspan" and "breakBefore" attributes can be perform for <rich:columns> the same way as for the <rich:columnt> component.
The <rich:columns> tag is initialized during components tree building process. This process precedes page rendering at "Render Response" JSF phase. To be rendered properly the component needs all it variables to be initialized while the components tree is being building. A javax.servlet.jsp.JspTagException occurs if <rich:columns> uses variables passed from other components, if these variables are initialized during rendering. Thus, when <rich:columns> is asking for such variables they do not already exist. Use <c:forEach> JSP standard tag as workaround. Compare two examples below.
This code calls the exception:
...
<rich:dataTable value="#{bean.data}" var="var">
<rich:columns value="#{var.columns}">
...
</rich:columns>
</rich:dataTable>
...
This code works properly:
...
<c:forEach items="#{bean.data}" var="var">
<rich:columns value="#{var.columns}">
...
</rich:columns>
</c:forEach>
...
Since 3.3.0GA <rich:columns> requires explicit definition of "id" for children components to ensure that decode process works properly. The example of how you can define unique "id" for children component:
...
<rich:columns value="#{bean.columns}" var="col" index="ind" ... >
<h:inputText id="input#{ind}" value="">
<a4j:support id="support#{ind}" event="onchange" reRender="someId" />
</h:inputText>
</rich:columns>
...
Only if "id" defined as shown above Ajax after onchange event will be processed as expected.
Sorting and filtering for the <rich:columns> component works the same as for <rich:column> . See the "Sorting and Filtering" section.
Table of <rich:columns> attributes.
Table 6.33. Component Identification Parameters
Name | Value |
---|---|
component-type | org.richfaces.Column |
tag-class | org.richfaces.taglib.ColumnsTagHandler |
Table 6.34. Facets
Facet name | Description |
---|---|
header | Defines the header content |
footer | Defines the footer content |
Custom style classes as well as skin parameters for <rich:columns> are the same as for the <rich:dataTable> component.
You can find all necessary information about style classes redefinition in Definition of Custom Style Classes section.
On the component LiveDemo page you can find an additional information on the <rich:columns> component usage.