6.21.  < a4j:repeat >

6.21.1. Description

The <a4j:repeat> component implements a basic iteration component allowing to update a set of its children with AJAX.

Table 6.41. a4j : repeat attributes

Attribute NameDescription
ajaxKeysThis attribute defines row keys that are updated after an AJAX request.
bindingThe attribute takes a value-binding expression for a component property of a backing bean
componentStateIt defines EL-binding for a component state for saving or redefinition.
firstA zero-relative row number of the first row to display
idEvery component may have a unique id that is automatically created if omitted
renderedIf "false", this component is not rendered
rowKeyConverterrowKeyConverter
rowKeyVarThe attribute provides access to a row key in a Request scope.
rowsA number of rows to display, or zero for all remaining rows in the table
stateVarThe attribute provides access to a component state on the client side.
valueThe current value for this component.
varA request-scope attribute via which the data object for the current row will be used when iterating

Table 6.42. Component identification parameters

NameValue
component-typeorg.ajax4jsf.Repeat
component-familyjavax.faces.Data
component-classorg.ajax4jsf.component.html.HtmlAjaxRepeat
renderer-typeorg.ajax4jsf.components.RepeatRenderer


6.21.2. Creating on a page

The component definition on a page is the same as for the facelets component:


<a4j:repeat id="detail" value="#{bean.props}" var="detail">
    <h:outputText value="#{detail.someProperty}"/>
</a4j:repeat>

The output is generated according to a collection contained in bean.props with the detail key passed to child components.

6.21.3. Creating the Component Dynamically Using Java

Example:


import org.ajax4jsf.component.html.HtmlAjaxRepeat;
...
HtmlAjaxRepeat repeater = new HtmlAjaxRepeat ();
...

6.21.4. Key attributes and ways of usage

The main difference of this component from iterative components of other libraries is a special "ajaxKeys" attribute. This attribute defines row keys that are updated after an Ajax request. As a result it becomes easier to update several child components separately without updating the whole page.


...
    <a4j:poll intervall="1000" action="#{repeater.action}" reRender="text">
        <table>
            <tbody>
                <a4j:repeat value="#{bean.props}" var="detail" ajaxKeys="#{repeater.ajaxedRowsSet}">
                    <tr>                
                        <td>
                            <h:outputText value="detail.someProperty" id="text"/>
                        </td>                            
                    </tr>
                </a4j:repeat>
            </tbody>
        </table>
    </a4j:poll>
...

Thus, a list with a table structure from bean.props is output.

In the above-mentioned example the component <a4j:poll> sends Ajax requests every second, calling the action method of the repeater bean.

Note:

The <a4j:repeater> component is defined as fully updated, but really updated there are only the row keys which rowKeys includes into the set ajaxRowSet defined in the "ajaxKeys" attribute

The set could be defined during the action method processing using data on a model from the property repeater.myRepeat

One more benefit of this component is absence of strictly defined markup as JSF HTML DataTable and TOMAHAWK DataTable has, hence the components could be used more flexibly anywhere where it's necessary to output the results of selection from some collection.

The next example shows collection output as a plain HTML list


<ul>
      <a4j:repeat ...>
        <li>...<li/>
         ...
        <li>...<li/>
      </a4j:repeat>
</ul>

All other general attributes are defined according to the similar attributes of iterative components ( <h:dataTable> or <ui:repeat> ) and are used in the same way.

6.21.5. Relevant resources links

Here you can see the example of <a4j:repeat> usage and sources for the given example.