org.displaytag.tags
Class TableTag

java.lang.Object
  extended by javax.servlet.jsp.tagext.TagSupport
      extended by javax.servlet.jsp.tagext.BodyTagSupport
          extended by org.displaytag.tags.TemplateTag
              extended by org.displaytag.tags.HtmlTableTag
                  extended by org.displaytag.tags.TableTag
All Implemented Interfaces:
java.io.Serializable, javax.servlet.jsp.tagext.BodyTag, javax.servlet.jsp.tagext.IterationTag, javax.servlet.jsp.tagext.JspTag, javax.servlet.jsp.tagext.Tag
Direct Known Subclasses:
ELTableTag

public class TableTag
extends HtmlTableTag

This tag takes a list of objects and creates a table to display those objects. With the help of column tags, you simply provide the name of properties (get Methods) that are called against the objects in your list that gets displayed. This tag works very much like the struts iterator tag, most of the attributes have the same name and functionality as the struts tag.

Version:
$Revision: 1144 $ ($Author: fgiust $)
Author:
mraible, Fabrizio Giustina
See Also:
Serialized Form

Field Summary
static java.lang.String FILTER_CONTENT_OVERRIDE_BODY
          If this variable is found in the request, assume the export filter is enabled.
protected  java.lang.Object list
          Object (collection, list) on which the table is based.
protected  java.lang.Object listAttribute
          Object (collection, list) on which the table is based.
static java.lang.String PAGE_ATTRIBUTE_MEDIA
          name of the attribute added to page scope when exporting, containing an MediaTypeEnum this can be used in column content to detect the output type and to return different data when exporting.
 
Fields inherited from class javax.servlet.jsp.tagext.BodyTagSupport
bodyContent
 
Fields inherited from class javax.servlet.jsp.tagext.TagSupport
id, pageContext
 
Fields inherited from interface javax.servlet.jsp.tagext.BodyTag
EVAL_BODY_BUFFERED, EVAL_BODY_TAG
 
Fields inherited from interface javax.servlet.jsp.tagext.IterationTag
EVAL_BODY_AGAIN
 
Fields inherited from interface javax.servlet.jsp.tagext.Tag
EVAL_BODY_INCLUDE, EVAL_PAGE, SKIP_BODY, SKIP_PAGE
 
Constructor Summary
TableTag()
           
 
Method Summary
 void addCell(Cell cell)
          Adds a cell to the current row.
 void addColumn(HeaderCell column)
          Called by interior column tags to help this tag figure out how it is supposed to display the information in the List it is supposed to display.
 int doAfterBody()
           
 int doEndTag()
          Draw the table.
protected  int doExport()
          Called when data are not displayed in a html page but should be exported.
protected  int doIteration()
          Utility method that is used by both doStartTag() and doAfterBody() to perform an iteration.
 int doStartTag()
          When the tag starts, we just initialize some of our variables, and do a little bit of error checking to make sure that the user is not trying to give us parameters that we don't expect.
protected  Href getBaseHref()
          Returns the base href with parameters.
 CaptionTag getCaptionTag()
          Obtain the child caption tag.
protected  java.lang.String getName()
          Returns the name.
protected  TableProperties getProperties()
          Returns the properties.
 TableModel getTableModel()
          Get the table model for this tag.
 java.util.Map getTotals()
          Get the column totals Map.
 java.lang.String getUid()
          Returns the unique id used to identify for this table.
 java.lang.String getVarTotals()
          Get the name that the totals should be stored under.
protected  void initHref(RequestHelper requestHelper)
          init the href object used to generate all the links for pagination, sorting, exporting.
protected  boolean isEmpty()
          Is the current row empty?
protected  boolean isFirstIteration()
          Is this the first iteration?
protected  boolean isIncludedRow()
          Is the current row included in the "to-be-evaluated" range? Called by nested ColumnTags.
protected  boolean isLastIteration()
          Is this the last iteration?
 void release()
           
 void setCaption(java.lang.String string)
          Sets the content of the caption.
 void setCaptionTag(CaptionTag captionTag)
          Set the child caption tag.
 void setClearStatus(boolean clearStatus)
          Setter for clearStatus.
 void setDecorator(java.lang.String decorator)
          Setter for the decorator class name.
 void setDefaultorder(java.lang.String value)
          sets the sorting order for the sorted column.
 void setDefaultsort(int value)
          sets the index of the default sorted column.
 void setExcludedParams(java.lang.String value)
          Sets the list of parameter which should not be forwarded during sorting or pagination.
 void setExport(boolean value)
          Is export enabled?
 void setFooter(java.lang.String string)
          Sets the content of the footer.
 void setForm(java.lang.String form)
          Setter for form.
 void setKeepStatus(boolean keepStatus)
          Preserve the current page and sort across session?
 void setLength(int value)
          sets the number of items to be displayed in the page.
 void setList(java.lang.Object value)
          Deprecated. use setName() to get the object from the page or request scope instead of setting it directly here
 void setName(java.lang.Object value)
          Sets the name of the object to use for iteration.
 void setNameString(java.lang.String value)
          Sets the name of the object to use for iteration.
 void setOffset(int value)
          Setter for the list offset attribute.
 void setPagesize(int value)
          sets the number of items that should be displayed for a single page.
 void setPartialList(boolean partialList)
          tells display tag that the values contained in the list are the viewable data only, there may be more results not given to displaytag
 void setProperty(java.lang.String propertyName, java.lang.String propertyValue)
          Called by the setProperty tag to override some default behavior or text String.
 void setRequestURI(java.lang.String value)
          setter for the "requestURI" attribute.
 void setRequestURIcontext(boolean value)
          Setter for the "requestURIcontext" attribute.
 void setSize(java.lang.Object size)
          set the Integer containing the total size of the data displaytag is paginating
 void setSizeObjectName(java.lang.String sizeObjectName)
          set the name of the Integer in some scope containing the total size of the data to be paginated
 void setSort(java.lang.String value)
          setter for the "sort" attribute.
 void setUid(java.lang.String value)
          Sets the unique id used to identify for this table.
protected  void setupViewableData()
          This sets the list of all of the data that will be displayed on the page via the table tag.
 void setVarTotals(java.lang.String varTotalsName)
          The variable name in which the totals map is stored.
protected  void writeExport(ExportView exportView)
          Will write the export.
protected  void writeHTMLData()
          Uses HtmlTableWriter to write table called when data have to be displayed in a html page.
 
Methods inherited from class org.displaytag.tags.HtmlTableTag
addClass, getAttributeMap, setCellpadding, setCellspacing, setClass, setFrame, setHtmlId, setRules, setStyle, setSummary
 
Methods inherited from class org.displaytag.tags.TemplateTag
evaluateExpression
 
Methods inherited from class javax.servlet.jsp.tagext.BodyTagSupport
doInitBody, getBodyContent, getPreviousOut, setBodyContent
 
Methods inherited from class javax.servlet.jsp.tagext.TagSupport
findAncestorWithClass, getId, getParent, getValue, getValues, removeValue, setId, setPageContext, setParent, setValue
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.servlet.jsp.tagext.Tag
getParent, setPageContext, setParent
 

Field Detail

PAGE_ATTRIBUTE_MEDIA

public static final java.lang.String PAGE_ATTRIBUTE_MEDIA
name of the attribute added to page scope when exporting, containing an MediaTypeEnum this can be used in column content to detect the output type and to return different data when exporting.

See Also:
Constant Field Values

FILTER_CONTENT_OVERRIDE_BODY

public static final java.lang.String FILTER_CONTENT_OVERRIDE_BODY
If this variable is found in the request, assume the export filter is enabled.

See Also:
Constant Field Values

list

protected java.lang.Object list
Object (collection, list) on which the table is based. This is not set directly using a tag attribute and can be cleaned.


listAttribute

protected java.lang.Object listAttribute
Object (collection, list) on which the table is based. Set directly using the "list" attribute or evaluated from expression.

Constructor Detail

TableTag

public TableTag()
Method Detail

isLastIteration

protected boolean isLastIteration()
Is this the last iteration?

Returns:
boolean true if this is the last iteration

setExcludedParams

public void setExcludedParams(java.lang.String value)
Sets the list of parameter which should not be forwarded during sorting or pagination.

Parameters:
value - whitespace separated list of parameters which should not be included (* matches all parameters)

setFooter

public void setFooter(java.lang.String string)
Sets the content of the footer. Called by a nested footer tag.

Parameters:
string - footer content

setCaption

public void setCaption(java.lang.String string)
Sets the content of the caption. Called by a nested caption tag.

Parameters:
string - caption content

setCaptionTag

public void setCaptionTag(CaptionTag captionTag)
Set the child caption tag.

Parameters:
captionTag - Child caption tag

getCaptionTag

public CaptionTag getCaptionTag()
Obtain the child caption tag.

Returns:
The child caption tag

isEmpty

protected boolean isEmpty()
Is the current row empty?

Returns:
true if the current row is empty

setKeepStatus

public void setKeepStatus(boolean keepStatus)
Preserve the current page and sort across session?

Parameters:
keepStatus - true to preserve paging and sorting

setClearStatus

public void setClearStatus(boolean clearStatus)
Setter for clearStatus.

Parameters:
clearStatus - The clearStatus to set.

setForm

public void setForm(java.lang.String form)
Setter for form.

Parameters:
post - The form to set.

setSize

public void setSize(java.lang.Object size)
set the Integer containing the total size of the data displaytag is paginating

Parameters:
size - Integer containing the total size of the data

setSizeObjectName

public void setSizeObjectName(java.lang.String sizeObjectName)
set the name of the Integer in some scope containing the total size of the data to be paginated

Parameters:
sizeObjectName - name of the Integer containing the total size of the data to be paginated

setSort

public void setSort(java.lang.String value)
             throws InvalidTagAttributeValueException
setter for the "sort" attribute.

Parameters:
value - "page" (sort a single page) or "list" (sort the full list)
Throws:
InvalidTagAttributeValueException - if value is not "page" or "list"

setRequestURI

public void setRequestURI(java.lang.String value)
setter for the "requestURI" attribute. Context path is automatically added to path starting with "/".

Parameters:
value - base URI for creating links

setRequestURIcontext

public void setRequestURIcontext(boolean value)
Setter for the "requestURIcontext" attribute.

Parameters:
value - base URI for creating links

setList

public void setList(java.lang.Object value)
Deprecated. use setName() to get the object from the page or request scope instead of setting it directly here

Used to directly set a list (or any object you can iterate on).

Parameters:
value - Object

setName

public void setName(java.lang.Object value)
Sets the name of the object to use for iteration.

Parameters:
value - name of the object to use for iteration (can contain expression). It also supports direct setting of a list, for jsp 2.0 containers where users can set up a data source here using EL expressions.

setNameString

public void setNameString(java.lang.String value)
Sets the name of the object to use for iteration. This setter is needed for jsp 1.1 container which doesn't support the String - Object conversion. The bean info class will swith to this setter.

Parameters:
value - name of the object

setDefaultorder

public void setDefaultorder(java.lang.String value)
                     throws InvalidTagAttributeValueException
sets the sorting order for the sorted column.

Parameters:
value - "ascending" or "descending"
Throws:
InvalidTagAttributeValueException - if value is not one of "ascending" or "descending"

setDecorator

public void setDecorator(java.lang.String decorator)
Setter for the decorator class name.

Parameters:
decorator - fully qualified name of the table decorator to use

setExport

public void setExport(boolean value)
Is export enabled?

Parameters:
value - true if export should be enabled

setVarTotals

public void setVarTotals(java.lang.String varTotalsName)
The variable name in which the totals map is stored.

Parameters:
varTotalsName - the value

getVarTotals

public java.lang.String getVarTotals()
Get the name that the totals should be stored under.

Returns:
the var name in pageContext

setLength

public void setLength(int value)
sets the number of items to be displayed in the page.

Parameters:
value - number of items to display in a page

setDefaultsort

public void setDefaultsort(int value)
sets the index of the default sorted column.

Parameters:
value - index of the column to sort

setPagesize

public void setPagesize(int value)
sets the number of items that should be displayed for a single page.

Parameters:
value - number of items that should be displayed for a single page

setPartialList

public void setPartialList(boolean partialList)
tells display tag that the values contained in the list are the viewable data only, there may be more results not given to displaytag

Parameters:
partialList - boolean value telling us there may be more data not given to displaytag

setOffset

public void setOffset(int value)
Setter for the list offset attribute.

Parameters:
value - String

setUid

public void setUid(java.lang.String value)
Sets the unique id used to identify for this table.

Parameters:
value - String

getUid

public java.lang.String getUid()
Returns the unique id used to identify for this table.

Returns:
id for this table

getProperties

protected TableProperties getProperties()
Returns the properties.

Returns:
TableProperties

getBaseHref

protected Href getBaseHref()
Returns the base href with parameters. This is the instance used for links, need to be cloned before being modified.

Returns:
base Href with parameters

addColumn

public void addColumn(HeaderCell column)
Called by interior column tags to help this tag figure out how it is supposed to display the information in the List it is supposed to display.

Parameters:
column - an internal tag describing a column in this tableview

addCell

public void addCell(Cell cell)
Adds a cell to the current row. This method is usually called by a contained ColumnTag

Parameters:
cell - Cell to add to the current row

isFirstIteration

protected boolean isFirstIteration()
Is this the first iteration?

Returns:
boolean true if this is the first iteration

doStartTag

public int doStartTag()
               throws javax.servlet.jsp.JspException
When the tag starts, we just initialize some of our variables, and do a little bit of error checking to make sure that the user is not trying to give us parameters that we don't expect.

Specified by:
doStartTag in interface javax.servlet.jsp.tagext.Tag
Overrides:
doStartTag in class javax.servlet.jsp.tagext.BodyTagSupport
Returns:
int
Throws:
javax.servlet.jsp.JspException - generic exception
See Also:
Tag.doStartTag()

doAfterBody

public int doAfterBody()
Specified by:
doAfterBody in interface javax.servlet.jsp.tagext.IterationTag
Overrides:
doAfterBody in class javax.servlet.jsp.tagext.BodyTagSupport
See Also:
IterationTag.doAfterBody()

doIteration

protected int doIteration()
Utility method that is used by both doStartTag() and doAfterBody() to perform an iteration.

Returns:
int either EVAL_BODY_TAG or SKIP_BODY depending on whether another iteration is desired.

isIncludedRow

protected boolean isIncludedRow()
Is the current row included in the "to-be-evaluated" range? Called by nested ColumnTags. If false column body is skipped.

Returns:
true if the current row must be evaluated because is included in output or because is included in sorting.

initHref

protected void initHref(RequestHelper requestHelper)
init the href object used to generate all the links for pagination, sorting, exporting.

Parameters:
requestHelper - request helper used to extract the base Href

doEndTag

public int doEndTag()
             throws javax.servlet.jsp.JspException
Draw the table. This is where everything happens, we figure out what values we are supposed to be showing, we figure out how we are supposed to be showing them, then we draw them.

Specified by:
doEndTag in interface javax.servlet.jsp.tagext.Tag
Overrides:
doEndTag in class javax.servlet.jsp.tagext.BodyTagSupport
Returns:
int
Throws:
javax.servlet.jsp.JspException - generic exception
See Also:
Tag.doEndTag()

doExport

protected int doExport()
                throws javax.servlet.jsp.JspException
Called when data are not displayed in a html page but should be exported.

Returns:
int SKIP_PAGE
Throws:
javax.servlet.jsp.JspException - generic exception

writeExport

protected void writeExport(ExportView exportView)
                    throws java.io.IOException,
                           javax.servlet.jsp.JspException
Will write the export. The default behavior is to write directly to the response. If the ResponseOverrideFilter is configured for this request, will instead write the exported content to a map in the Request object.

Parameters:
exportView - export view
Throws:
javax.servlet.jsp.JspException - for problem in clearing the response or for invalid export views
java.io.IOException - exception thrown when writing content to the response

setupViewableData

protected void setupViewableData()
This sets the list of all of the data that will be displayed on the page via the table tag. This might include just a subset of the total data in the list due to to paging being active, or the user asking us to just show a subset, etc...


writeHTMLData

protected void writeHTMLData()
                      throws javax.servlet.jsp.JspException
Uses HtmlTableWriter to write table called when data have to be displayed in a html page.

Throws:
javax.servlet.jsp.JspException - generic exception

getTotals

public java.util.Map getTotals()
Get the column totals Map. If there is no varTotals defined, there are no totals.

Returns:
a Map of totals where the key is the column number and the value is the total for that column

getTableModel

public TableModel getTableModel()
Get the table model for this tag. Sometimes required by local tags that cooperate with DT. USE THIS METHOD WITH EXTREME CAUTION; IT PROVIDES ACCESS TO THE INTERNALS OF DISPLAYTAG, WHICH ARE NOT TO BE CONSIDERED STABLE PUBLIC INTERFACES.

Returns:
the TableModel

setProperty

public void setProperty(java.lang.String propertyName,
                        java.lang.String propertyValue)
Called by the setProperty tag to override some default behavior or text String.

Parameters:
propertyName - String property name
propertyValue - String property value

release

public void release()
Specified by:
release in interface javax.servlet.jsp.tagext.Tag
Overrides:
release in class HtmlTableTag
See Also:
Tag.release()

getName

protected java.lang.String getName()
Returns the name.

Returns:
String


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