Monday, January 28, 2013

Dynamic Panels with a4j:repeat


With the imminent 4.3.0.Final release of RichFaces, we will be providing developers with the ability to dynamically create <rich:togglePanel>, <rich:accordion>, and <rich:tabPanel> panel items dynamically with the <a4j:repeat> tag.

<a4j:repeat> vs. <c:forEach>

Creating the above panels from a backing bean list has always been possible with RichFaces 4 using the JSTL <c:forEach> tag, so why have we bothered adding support for creating such panels with the <a4j:repeat> tag? The answer to that requires an understanding of when the JSTL tags are evaluated during the creation of the JSF component tree, and subsequent page render:

TL;DR: JSTL tags are evaluated during the compilation of the Facelet, during the construction of the component tree, whereas <a4j:repeat> is evaluated during the render phase of the JSF life-cycle.

For a great/detailed explanation of the JSTL tag / Life-cycle interaction, I’ll refer you to this blog post.

So if you are currently using the <c:forEach> tag to define dynamic child toggle panel items, and are noticing an issue on post-back when the list backing the panel items may have changed, be sure to try using the tag instead.

Using the <a4j:repeat>

Refer to the showcase snapshot for examples of using the <a4j:repeat> tag with the above listed family of toggle panel items:

The 4.3 release

RichFaces 4.3.0.CR2 is currently available, and RichFaces 4.3.0.Final will be available shortly. Please take the time to take try out the <a4j:repeat> tag to define relating toggle panel items, and give us your feedback for the new features and bug fixes via the RichFaces forum or issue tracker.