Description

This component allows you to render a part of the page to a buffer, and then use the buffer later.

Screen Shot

Not a Visual Component

API

component-family

javax.faces.Data

renderer-type

org.apache.myfaces.Buffer

component-class

org.apache.myfaces.custom.buffer.Buffer

renderer-class

org.apache.myfaces.custom.buffer.BufferRenderer

tag-class

org.apache.myfaces.custom.buffer.BufferTag

Usage

Obviously you can use buffer to reduce copy and paste reusability which is a very bad practice, but another scenario of buffer is handling some lifecycle problems, for example if you want to view a Data Scroller before your Data Table, You can't have dataScroller tag BEFORE the table tag in your JSP files, as it can't find the not yet rendered table. So, the solution is that you first render the table to a buffer, then you render the dataScroller, and then you render the buffer's content. That way, the dataScroller will appear before the table even though it was rendered after it.

Syntax

<t:buffer>

<t:buffer into="[variable name]">
   ... nested tags...
</t:buffer>

Instructions

Just nest elements to buffer into a <t:buffer> element.

Attributes

name

required

description

into

true

name of variable or bean for holding buffer data

Configuration

Don't need any extra configuration.

Notes and Known issues

Examples

the complete source of these two exmaples including managed beans can be found in myfaces examples, in the buffer.jsp

Simple Buffer

<t:buffer into="#{buffer1}">
   <t:div><h:outputText value="Buffer One"/></t:div>
</t:buffer>

<t:buffer into="#{buffer2}">
   <t:div><h:outputText value="Buffer Two"/></t:div>
</t:buffer>

<h:outputText value="#{buffer2}" escape="false"/>
<h:outputText value="#{buffer1}" escape="false"/>
<h:outputText value="#{buffer2}" escape="false"/>

the result will be

Buffer Two
Buffer One
Buffer Two

Data Scroller

This is more advanced use of buffer to view a data scroller before and after a table, both table and data scroller are send to a buffer, then the top data scroller, table and bottom data scroller are all displayed with output text, buffer is used twice here, first for solving the problem of decency on future tags, second to avoid creating and rendering data scroller twice (caching).

<t:buffer into="#{table}">
   <t:dataTable rows="10" ...>
      ...
   </t:dataTable>
</t:buffer>

<t:buffer into="#{tableScroller}">
   <t:dataScroller ...>
   ....
   </t:dataScroller>
</t:buffer>

<h:outputText value="#{tableScroller}" escape="false" />
<h:outputText value="#{table}" escape="false" />
<h:outputText value="#{tableScroller}" escape="false" />

the following is a sample from myfaces examples using the above example:

http://arash.rajaeeyan.googlepages.com/TomahawkBufferExample.PNG

FAQ

Additional Information

Buffer (last edited 2009-09-20 23:00:52 by localhost)