📄 tabletag.java
字号:
/**
* Licensed under the Artistic License; you may not use this file
* except in compliance with the License.
* You may obtain a copy of the License at
*
* http://displaytag.sourceforge.net/license.html
*
* THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
package org.displaytag.tags;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspTagException;
import javax.servlet.jsp.JspWriter;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.collections.IteratorUtils;
import org.apache.commons.lang.ObjectUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.math.LongRange;
import org.apache.commons.lang.math.NumberUtils;
import org.apache.commons.lang.math.Range;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.displaytag.Messages;
import org.displaytag.decorator.TableDecorator;
import org.displaytag.exception.ExportException;
import org.displaytag.exception.FactoryInstantiationException;
import org.displaytag.exception.InvalidTagAttributeValueException;
import org.displaytag.exception.WrappedRuntimeException;
import org.displaytag.export.BinaryExportView;
import org.displaytag.export.ExportView;
import org.displaytag.export.ExportViewFactory;
import org.displaytag.export.TextExportView;
import org.displaytag.model.Cell;
import org.displaytag.model.Column;
import org.displaytag.model.HeaderCell;
import org.displaytag.model.Row;
import org.displaytag.model.TableModel;
import org.displaytag.pagination.PaginatedList;
import org.displaytag.pagination.PaginatedListSmartListHelper;
import org.displaytag.pagination.SmartListHelper;
import org.displaytag.properties.MediaTypeEnum;
import org.displaytag.properties.SortOrderEnum;
import org.displaytag.properties.TableProperties;
import org.displaytag.render.HtmlTableWriter;
import org.displaytag.util.CollectionUtil;
import org.displaytag.util.DependencyChecker;
import org.displaytag.util.Href;
import org.displaytag.util.ParamEncoder;
import org.displaytag.util.RequestHelper;
import org.displaytag.util.RequestHelperFactory;
import org.displaytag.util.TagConstants;
/**
* 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.
* @author mraible
* @author Fabrizio Giustina
* @version $Revision: 1025 $ ($Author: fgiust $)
*/
public class TableTag extends HtmlTableTag
{
/**
* 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.
*/
public static final String PAGE_ATTRIBUTE_MEDIA = "mediaType"; //$NON-NLS-1$
/**
* If this variable is found in the request, assume the export filter is enabled.
*/
public static final String FILTER_CONTENT_OVERRIDE_BODY = //
"org.displaytag.filter.ResponseOverrideFilter.CONTENT_OVERRIDE_BODY"; //$NON-NLS-1$
/**
* D1597A17A6.
*/
private static final long serialVersionUID = 899149338534L;
/**
* logger.
*/
private static Log log = LogFactory.getLog(TableTag.class);
/**
* RequestHelperFactory instance used for link generation.
*/
private static RequestHelperFactory rhf;
/**
* Object (collection, list) on which the table is based. This is not set directly using a tag attribute and can be
* cleaned.
*/
protected Object list;
// -- start tag attributes --
/**
* Object (collection, list) on which the table is based. Set directly using the "list" attribute or evaluated from
* expression.
*/
protected Object listAttribute;
/**
* actual row number, updated during iteration.
*/
private int rowNumber = 1;
/**
* name of the object to use for iteration. Can contain expressions.
*/
private String name;
/**
* length of list to display.
*/
private int length;
/**
* table decorator class name.
*/
private String decoratorName;
/**
* page size.
*/
private int pagesize;
/**
* list contains only viewable data.
*/
private boolean partialList;
/**
* add export links.
*/
private boolean export;
/**
* list offset.
*/
private int offset;
/**
* Integer containing total size of the data displaytag is paginating
*/
private Object size;
/**
* Name of the Integer in some scope containing the size of the data displaytag is paginating
*/
private String sizeObjectName;
/**
* sort the full list?
*/
private Boolean sortFullTable;
/**
* are we doing any local sorting? (defaults to True)
*/
private boolean localSort = true;
/**
* Request uri.
*/
private String requestUri;
/**
* Prepend application context to generated links.
*/
private boolean dontAppendContext;
/**
* the index of the column sorted by default.
*/
private int defaultSortedColumn = -1;
/**
* the sorting order for the sorted column.
*/
private SortOrderEnum defaultSortOrder;
/**
* Name of parameter which should not be forwarded during sorting or pagination.
*/
private String excludedParams;
/**
* Unique table id.
*/
private String uid;
/**
* The variable name to store totals in.
*/
private String varTotals;
// -- end tag attributes --
/**
* table model - initialized in doStartTag().
*/
private TableModel tableModel;
/**
* current row.
*/
private Row currentRow;
/**
* next row.
*/
/**
* Used by various functions when the person wants to do paging - cleaned in doEndTag().
*/
private SmartListHelper listHelper;
/**
* base href used for links - set in initParameters().
*/
private Href baseHref;
/**
* table properties - set in doStartTag().
*/
private TableProperties properties;
/**
* page number - set in initParameters().
*/
private int pageNumber = 1;
/**
* Iterator on collection.
*/
private Iterator tableIterator;
/**
* export type - set in initParameters().
*/
private MediaTypeEnum currentMediaType;
/**
* daAfterBody() has been executed at least once?
*/
private boolean doAfterBodyExecuted;
/**
* The param encoder used to generate unique parameter names. Initialized at the first use of encodeParameter().
*/
private ParamEncoder paramEncoder;
/**
* Static footer added using the footer tag.
*/
private String footer;
/**
* Is this the last iteration we will be performing? We only output the footer on the last iteration.
*/
private boolean lastIteration;
/**
* Static caption added using the footer tag.
*/
private String caption;
/**
* Child caption tag.
*/
private CaptionTag captionTag;
/**
* Included row range. If no rows can be skipped the range is from 0 to Long.MAX_VALUE. Range check should be always
* done using containsLong(). This is an instance of org.apache.commons.lang.math.Range, but it's declared as Object
* to avoid runtime errors while Jasper tries to compile the page and commons lang 2.0 is not available. Commons
* lang version will be checked in the doStartTag() method in order to provide a more user friendly message.
*/
private Object filteredRows;
/**
* The paginated list containing the external pagination and sort parameters The presence of this paginated list is
* what determines if external pagination and sorting is used or not.
*/
private PaginatedList paginatedList;
/**
* Is this the last iteration?
* @return boolean <code>true</code> if this is the last iteration
*/
protected boolean isLastIteration()
{
return this.lastIteration;
}
/**
* Sets the list of parameter which should not be forwarded during sorting or pagination.
* @param value whitespace separated list of parameters which should not be included (* matches all parameters)
*/
public void setExcludedParams(String value)
{
this.excludedParams = value;
}
/**
* Sets the content of the footer. Called by a nested footer tag.
* @param string footer content
*/
public void setFooter(String string)
{
this.footer = string;
this.tableModel.setFooter(this.footer);
}
/**
* Sets the content of the caption. Called by a nested caption tag.
* @param string caption content
*/
public void setCaption(String string)
{
this.caption = string;
this.tableModel.setCaption(this.caption);
}
/**
* Set the child caption tag.
* @param captionTag Child caption tag
*/
public void setCaptionTag(CaptionTag captionTag)
{
this.captionTag = captionTag;
}
/**
* Obtain the child caption tag.
* @return The child caption tag
*/
public CaptionTag getCaptionTag()
{
return this.captionTag;
}
/**
* Is the current row empty?
* @return true if the current row is empty
*/
protected boolean isEmpty()
{
return this.currentRow == null;
}
/**
* set the Integer containing the total size of the data displaytag is paginating
* @param size Integer containing the total size of the data
*/
public void setSize(Object size)
{
if (size instanceof String)
{
this.sizeObjectName = (String) size;
}
else
{
this.size = size;
}
}
/**
* set the name of the Integer in some scope containing the total size of the data to be paginated
* @param sizeObjectName name of the Integer containing the total size of the data to be paginated
*/
public void setSizeObjectName(String sizeObjectName)
{
this.sizeObjectName = sizeObjectName;
}
/**
* setter for the "sort" attribute.
* @param value "page" (sort a single page) or "list" (sort the full list)
* @throws InvalidTagAttributeValueException if value is not "page" or "list"
*/
public void setSort(String value) throws InvalidTagAttributeValueException
{
if (TableTagParameters.SORT_AMOUNT_PAGE.equals(value))
{
this.sortFullTable = Boolean.FALSE;
}
else if (TableTagParameters.SORT_AMOUNT_LIST.equals(value))
{
this.sortFullTable = Boolean.TRUE;
}
else if (TableTagParameters.SORT_AMOUNT_EXTERNAL.equals(value))
{
this.localSort = false;
}
else
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -