org.displaytag.render
Class TableWriterTemplate

java.lang.Object
  extended by org.displaytag.render.TableWriterTemplate
Direct Known Subclasses:
TableWriterAdapter

public abstract class TableWriterTemplate
extends java.lang.Object

A template that encapsulates and drives the construction of a table based on a given table model and configuration. This class is meant to be extended by classes that build tables sharing the same structure, sorting, and grouping, but that write them in different formats and to various destinations. Subclasses must provide the format- and destination-specific implementations of the abstract methods this class calls to build a table. (Background: This class came about because our users wanted to export tables to Excel and PDF just as they were presented in HTML. It originates with the TableTagData.writeHTMLData method, factoring its logic so that it can be re-used by classes that write the tables as PDF, Excel, RTF and other formats. TableTagData.writeHTMLData now calls an HTML extension of this class to write tables in HTML format to a JSP page.)

Version:
$Id$
Author:
Jorge L. Barroso

Field Summary
static short GROUP_END
           
static short GROUP_NO_CHANGE
           
static short GROUP_START
           
static short GROUP_START_AND_END
           
protected static int NO_RESET_GROUP
           
 
Constructor Summary
TableWriterTemplate()
           
 
Method Summary
protected  short groupColumns(java.lang.String value, java.lang.String previous, java.lang.String next, int currentGroup)
          This takes a column value and grouping index as the argument.
protected abstract  void writeBottomBanner(TableModel model)
          Called by writeTable to write the table's footer.
protected abstract  void writeCaption(TableModel model)
          Called by writeTable to write the table's caption.
protected abstract  void writeColumnCloser(Column column)
          Called by writeTableBody to write the end of the column structure.
protected abstract  void writeColumnOpener(Column column)
          Called by writeTableBody to write the start of the column structure.
protected abstract  void writeColumnValue(java.lang.Object value, Column column)
          Called by writeTableBody to write a column's value.
protected abstract  void writeDecoratedRowFinish(TableModel model)
          Called by writeTableBody to decorate the table.
protected abstract  void writeDecoratedRowStart(TableModel model)
          Called by writeTableBody to write to decorate the table.
protected abstract  void writeDecoratedTableFinish(TableModel model)
          Called by writeTable to decorate the table.
protected abstract  void writeEmptyListMessage(java.lang.String emptyListMessage)
          Called by writeTable to write a message explaining that the table model contains no data.
protected abstract  void writeEmptyListRowMessage(java.lang.String message)
          Called by writeTableBody to write a message explaining that the row contains no data.
protected abstract  void writePostBodyFooter(TableModel model)
          Called by writeTable to write table footer after table body.
protected abstract  void writePreBodyFooter(TableModel model)
          Called by writeTable to write table footer before table body.
protected abstract  void writeRowCloser(Row row)
          Called by writeTableBody to write the end of the row structure.
protected abstract  void writeRowOpener(Row row)
          Called by writeTableBody to write the start of the row structure.
protected abstract  void writeRowWithNoColumns(java.lang.String value)
          Called by writeTableBody to write a row that has no columns.
 void writeTable(TableModel model, java.lang.String id)
          Given a table model, this method creates a table, sorting and grouping it per its configuration, while delegating where and how it writes the table to subclass objects.
protected abstract  void writeTableBodyCloser(TableModel model)
          Called by writeTable to write the end of the table's body.
protected abstract  void writeTableBodyOpener(TableModel model)
          Called by writeTable to write the start of the table's body.
protected abstract  void writeTableCloser(TableModel model)
          Called by writeTable to write the end of the table's structure.
protected abstract  void writeTableHeader(TableModel model)
          Called by writeTable to write the table's header columns.
protected abstract  void writeTableOpener(TableModel model)
          Called by writeTable to write the start of the table structure.
protected abstract  void writeTopBanner(TableModel model)
          Called by writeTable to write a summary of the search result this table reports and the table's pagination interface.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

GROUP_START

public static final short GROUP_START
See Also:
Constant Field Values

GROUP_END

public static final short GROUP_END
See Also:
Constant Field Values

GROUP_START_AND_END

public static final short GROUP_START_AND_END
See Also:
Constant Field Values

GROUP_NO_CHANGE

public static final short GROUP_NO_CHANGE
See Also:
Constant Field Values

NO_RESET_GROUP

protected static final int NO_RESET_GROUP
See Also:
Constant Field Values
Constructor Detail

TableWriterTemplate

public TableWriterTemplate()
Method Detail

writeTable

public void writeTable(TableModel model,
                       java.lang.String id)
                throws javax.servlet.jsp.JspException
Given a table model, this method creates a table, sorting and grouping it per its configuration, while delegating where and how it writes the table to subclass objects. (Background: This method refactors TableTagData.writeHTMLData method. See above.)

Parameters:
model - The table model used to build the table.
id - This table's page id.
Throws:
javax.servlet.jsp.JspException - if any exception thrown while constructing the tablei, it is caught and rethrown as a JspException. Extension classes may throw all sorts of exceptions, depending on their respective formats and destinations.

writeEmptyListMessage

protected abstract void writeEmptyListMessage(java.lang.String emptyListMessage)
                                       throws java.lang.Exception
Called by writeTable to write a message explaining that the table model contains no data.

Parameters:
emptyListMessage - A message explaining that the table model contains no data.
Throws:
java.lang.Exception - if it encounters an error while writing.

writeTopBanner

protected abstract void writeTopBanner(TableModel model)
                                throws java.lang.Exception
Called by writeTable to write a summary of the search result this table reports and the table's pagination interface.

Parameters:
model - The table model for which the banner is written.
Throws:
java.lang.Exception - if it encounters an error while writing.

writeTableOpener

protected abstract void writeTableOpener(TableModel model)
                                  throws java.lang.Exception
Called by writeTable to write the start of the table structure.

Parameters:
model - The table model for which the content is written.
Throws:
java.lang.Exception - if it encounters an error while writing.

writeCaption

protected abstract void writeCaption(TableModel model)
                              throws java.lang.Exception
Called by writeTable to write the table's caption.

Parameters:
model - The table model for which the content is written.
Throws:
java.lang.Exception - if it encounters an error while writing.

writeTableHeader

protected abstract void writeTableHeader(TableModel model)
                                  throws java.lang.Exception
Called by writeTable to write the table's header columns.

Parameters:
model - The table model for which the content is written.
Throws:
java.lang.Exception - if it encounters an error while writing.

writePreBodyFooter

protected abstract void writePreBodyFooter(TableModel model)
                                    throws java.lang.Exception
Called by writeTable to write table footer before table body.

Parameters:
model - The table model for which the content is written.
Throws:
java.lang.Exception - if it encounters an error while writing.

writeTableBodyOpener

protected abstract void writeTableBodyOpener(TableModel model)
                                      throws java.lang.Exception
Called by writeTable to write the start of the table's body.

Parameters:
model - The table model for which the content is written.
Throws:
java.lang.Exception - if it encounters an error while writing.

writeTableBodyCloser

protected abstract void writeTableBodyCloser(TableModel model)
                                      throws java.lang.Exception
Called by writeTable to write the end of the table's body.

Parameters:
model - The table model for which the content is written.
Throws:
java.lang.Exception - if it encounters an error while writing.

writePostBodyFooter

protected abstract void writePostBodyFooter(TableModel model)
                                     throws java.lang.Exception
Called by writeTable to write table footer after table body.

Parameters:
model - The table model for which the content is written.
Throws:
java.lang.Exception - if it encounters an error while writing.

writeTableCloser

protected abstract void writeTableCloser(TableModel model)
                                  throws java.lang.Exception
Called by writeTable to write the end of the table's structure.

Parameters:
model - The table model for which the content is written.
Throws:
java.lang.Exception - if it encounters an error while writing.

writeDecoratedTableFinish

protected abstract void writeDecoratedTableFinish(TableModel model)
                                           throws java.lang.Exception
Called by writeTable to decorate the table.

Parameters:
model - The table model for which the content is written.
Throws:
java.lang.Exception - if it encounters an error while writing.

writeBottomBanner

protected abstract void writeBottomBanner(TableModel model)
                                   throws java.lang.Exception
Called by writeTable to write the table's footer.

Parameters:
model - The table model for which the content is written.
Throws:
java.lang.Exception - if it encounters an error while writing.

writeDecoratedRowStart

protected abstract void writeDecoratedRowStart(TableModel model)
                                        throws java.lang.Exception
Called by writeTableBody to write to decorate the table.

Parameters:
model - The table model for which the content is written.
Throws:
java.lang.Exception - if it encounters an error while writing.

writeRowOpener

protected abstract void writeRowOpener(Row row)
                                throws java.lang.Exception
Called by writeTableBody to write the start of the row structure.

Parameters:
row - The table row for which the content is written.
Throws:
java.lang.Exception - if it encounters an error while writing.

writeColumnOpener

protected abstract void writeColumnOpener(Column column)
                                   throws java.lang.Exception
Called by writeTableBody to write the start of the column structure.

Parameters:
column - The table column for which the content is written.
Throws:
java.lang.Exception - if it encounters an error while writing.

writeColumnValue

protected abstract void writeColumnValue(java.lang.Object value,
                                         Column column)
                                  throws java.lang.Exception
Called by writeTableBody to write a column's value.

Parameters:
value - The column value.
column - The table column for which the content is written.
Throws:
java.lang.Exception - if it encounters an error while writing.

writeColumnCloser

protected abstract void writeColumnCloser(Column column)
                                   throws java.lang.Exception
Called by writeTableBody to write the end of the column structure.

Parameters:
column - The table column for which the content is written.
Throws:
java.lang.Exception - if it encounters an error while writing.

writeRowWithNoColumns

protected abstract void writeRowWithNoColumns(java.lang.String value)
                                       throws java.lang.Exception
Called by writeTableBody to write a row that has no columns.

Parameters:
value - The row value.
Throws:
java.lang.Exception - if it encounters an error while writing.

writeRowCloser

protected abstract void writeRowCloser(Row row)
                                throws java.lang.Exception
Called by writeTableBody to write the end of the row structure.

Parameters:
row - The table row for which the content is written.
Throws:
java.lang.Exception - if it encounters an error while writing.

writeDecoratedRowFinish

protected abstract void writeDecoratedRowFinish(TableModel model)
                                         throws java.lang.Exception
Called by writeTableBody to decorate the table.

Parameters:
model - The table model for which the content is written.
Throws:
java.lang.Exception - if it encounters an error while writing.

writeEmptyListRowMessage

protected abstract void writeEmptyListRowMessage(java.lang.String message)
                                          throws java.lang.Exception
Called by writeTableBody to write a message explaining that the row contains no data.

Parameters:
message - The message explaining that the row contains no data.
Throws:
java.lang.Exception - if it encounters an error while writing.

groupColumns

protected short groupColumns(java.lang.String value,
                             java.lang.String previous,
                             java.lang.String next,
                             int currentGroup)
This takes a column value and grouping index as the argument. It then groups the column and returns the appropriate string back to the caller.

Parameters:
value - String current cell value
Returns:
String


Copyright © 2002-2010 the Displaytag team. All Rights Reserved.