📄 tabletag.java
字号:
throw new InvalidTagAttributeValueException(getClass(), "sort", value); //$NON-NLS-1$
}
}
/**
* setter for the "requestURI" attribute. Context path is automatically added to path starting with "/".
* @param value base URI for creating links
*/
public void setRequestURI(String value)
{
this.requestUri = value;
}
/**
* Setter for the "requestURIcontext" attribute.
* @param value base URI for creating links
*/
public void setRequestURIcontext(boolean value)
{
this.dontAppendContext = !value;
}
/**
* Used to directly set a list (or any object you can iterate on).
* @param value Object
* @deprecated use setName() to get the object from the page or request scope instead of setting it directly here
*/
public void setList(Object value)
{
this.listAttribute = value;
}
/**
* Sets the name of the object to use for iteration.
* @param 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.
*/
public void setName(Object value)
{
if (value instanceof String)
{
// ok, assuming this is the name of the object
this.name = (String) value;
}
else
{
// is this the list?
this.list = 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.
* @param value name of the object
*/
public void setNameString(String value)
{
this.name = value;
}
/**
* sets the sorting order for the sorted column.
* @param value "ascending" or "descending"
* @throws InvalidTagAttributeValueException if value is not one of "ascending" or "descending"
*/
public void setDefaultorder(String value) throws InvalidTagAttributeValueException
{
this.defaultSortOrder = SortOrderEnum.fromName(value);
if (this.defaultSortOrder == null)
{
throw new InvalidTagAttributeValueException(getClass(), "defaultorder", value); //$NON-NLS-1$
}
}
/**
* Setter for the decorator class name.
* @param decorator fully qualified name of the table decorator to use
*/
public void setDecorator(String decorator)
{
this.decoratorName = decorator;
}
/**
* Is export enabled?
* @param value <code>true</code> if export should be enabled
*/
public void setExport(boolean value)
{
this.export = value;
}
/**
* The variable name in which the totals map is stored.
* @param varTotalsName the value
*/
public void setVarTotals(String varTotalsName)
{
this.varTotals = varTotalsName;
}
/**
* Get the name that the totals should be stored under.
* @return the var name in pageContext
*/
public String getVarTotals()
{
return this.varTotals;
}
/**
* sets the number of items to be displayed in the page.
* @param value number of items to display in a page
*/
public void setLength(int value)
{
this.length = value;
}
/**
* sets the index of the default sorted column.
* @param value index of the column to sort
*/
public void setDefaultsort(int value)
{
// subtract one (internal index is 0 based)
this.defaultSortedColumn = value - 1;
}
/**
* sets the number of items that should be displayed for a single page.
* @param value number of items that should be displayed for a single page
*/
public void setPagesize(int value)
{
this.pagesize = value;
}
/**
* tells display tag that the values contained in the list are the viewable data only, there may be more results not
* given to displaytag
* @param partialList boolean value telling us there may be more data not given to displaytag
*/
public void setPartialList(boolean partialList)
{
this.partialList = partialList;
}
/**
* Setter for the list offset attribute.
* @param value String
*/
public void setOffset(int value)
{
if (value < 1)
{
// negative values has no meaning, simply treat them as 0
this.offset = 0;
}
else
{
this.offset = value - 1;
}
}
/**
* Sets the unique id used to identify for this table.
* @param value String
*/
public void setUid(String value)
{
this.uid = value;
}
/**
* Returns the unique id used to identify for this table.
* @return id for this table
*/
public String getUid()
{
return this.uid;
}
/**
* Returns the properties.
* @return TableProperties
*/
protected TableProperties getProperties()
{
return this.properties;
}
/**
* Returns the base href with parameters. This is the instance used for links, need to be cloned before being
* modified.
* @return base Href with parameters
*/
protected Href getBaseHref()
{
return this.baseHref;
}
/**
* 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.
* @param column an internal tag describing a column in this tableview
*/
public void addColumn(HeaderCell column)
{
if (log.isDebugEnabled())
{
log.debug("[" + getUid() + "] addColumn " + column);
}
if ((this.paginatedList != null) && (column.getSortable()))
{
String sortCriterion = paginatedList.getSortCriterion();
String sortProperty = column.getSortProperty();
if (sortProperty == null)
{
sortProperty = column.getBeanPropertyName();
}
if ((sortCriterion != null) && sortCriterion.equals(sortProperty))
{
this.tableModel.setSortedColumnNumber(this.tableModel.getNumberOfColumns());
column.setAlreadySorted();
}
}
this.tableModel.addColumnHeader(column);
}
/**
* Adds a cell to the current row. This method is usually called by a contained ColumnTag
* @param cell Cell to add to the current row
*/
public void addCell(Cell cell)
{
// check if null: could be null if list is empty, we don't need to fill rows
if (this.currentRow != null)
{
int columnNumber = this.currentRow.getCellList().size();
this.currentRow.addCell(cell);
// just be sure that the number of columns has not been altered by conditionally including column tags in
// different rows. This is not supported, but better avoid IndexOutOfBounds...
if (columnNumber < tableModel.getHeaderCellList().size())
{
HeaderCell header = (HeaderCell) tableModel.getHeaderCellList().get(columnNumber);
header.addCell(new Column(header, cell, currentRow));
}
}
}
/**
* Is this the first iteration?
* @return boolean <code>true</code> if this is the first iteration
*/
protected boolean isFirstIteration()
{
if (log.isDebugEnabled())
{
log.debug("["
+ getUid()
+ "] first iteration="
+ (this.rowNumber == 1)
+ " (row number="
+ this.rowNumber
+ ")");
}
// in first iteration this.rowNumber is 1
// (this.rowNumber is incremented in doAfterBody)
return this.rowNumber == 1;
}
/**
* 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.
* @return int
* @throws JspException generic exception
* @see javax.servlet.jsp.tagext.Tag#doStartTag()
*/
public int doStartTag() throws JspException
{
DependencyChecker.check();
// needed before column processing, elsewhere registered views will not be added
ExportViewFactory.getInstance();
if (log.isDebugEnabled())
{
log.debug("[" + getUid() + "] doStartTag called");
}
this.properties = TableProperties.getInstance((HttpServletRequest) pageContext.getRequest());
this.tableModel = new TableModel(this.properties, pageContext.getResponse().getCharacterEncoding(), pageContext);
// copying id to the table model for logging
this.tableModel.setId(getUid());
initParameters();
this.tableModel.setMedia(this.currentMediaType);
Object previousMediaType = this.pageContext.getAttribute(PAGE_ATTRIBUTE_MEDIA);
// set the PAGE_ATTRIBUTE_MEDIA attribute in the page scope
if (previousMediaType == null || MediaTypeEnum.HTML.equals(previousMediaType))
{
if (log.isDebugEnabled())
{
log.debug("[" + getUid() + "] setting media [" + this.currentMediaType + "] in this.pageContext");
}
this.pageContext.setAttribute(PAGE_ATTRIBUTE_MEDIA, this.currentMediaType);
}
doIteration();
// always return EVAL_BODY_TAG to get column headers also if the table is empty
// using int to avoid deprecation error in compilation using j2ee 1.3
return 2;
}
/**
* @see javax.servlet.jsp.tagext.BodyTag#doAfterBody()
*/
public int doAfterBody()
{
// doAfterBody() has been called, body is not empty
this.doAfterBodyExecuted = true;
if (log.isDebugEnabled())
{
log.debug("[" + getUid() + "] doAfterBody called - iterating on row " + this.rowNumber);
}
// increment this.rowNumber
this.rowNumber++;
// Call doIteration() to do the common work
return doIteration();
}
/**
* Utility method that is used by both doStartTag() and doAfterBody() to perform an iteration.
* @return <code>int</code> either EVAL_BODY_TAG or SKIP_BODY depending on whether another iteration is desired.
*/
protected int doIteration()
{
if (log.isDebugEnabled())
{
log.debug("[" + getUid() + "] doIteration called");
}
// Row already filled?
if (this.currentRow != null)
{
// if yes add to table model and remove
this.tableModel.addRow(this.currentRow);
this.currentRow = null;
}
if (this.tableIterator.hasNext())
{
Object iteratedObject = this.tableIterator.next();
if (getUid() != null)
{
if ((iteratedObject != null))
{
// set object into this.pageContext
if (log.isDebugEnabled())
{
log.debug("[" + getUid() + "] setting attribute \"" + getUid() + "\" in pageContext");
}
this.pageContext.setAttribute(getUid(), iteratedObject);
}
else
{
// if row is null remove previous object
this.pageContext.removeAttribute(getUid());
}
// set the current row number into this.pageContext
this.pageContext.setAttribute(getUid() + TableTagExtraInfo.ROWNUM_SUFFIX, new Integer(this.rowNumber));
}
// Row object for Cell values
this.currentRow = new Row(iteratedObject, this.rowNumber);
this.lastIteration = !this.tableIterator.hasNext();
// new iteration
// using int to avoid deprecation error in compilation using j2ee 1.3
return 2;
}
this.lastIteration = true;
if (log.isDebugEnabled())
{
log.debug("[" + getUid() + "] doIteration() - iterator ended after " + (this.rowNumber - 1) + " rows");
}
// end iteration
return SKIP_BODY;
}
/**
* Reads parameters from the request and initialize all the needed table model attributes.
* @throws FactoryInstantiationException for problems in instantiating a RequestHelperFactory
*/
private void initParameters() throws JspTagException, FactoryInstantiationException
{
if (rhf == null)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -