📄 treetag.java
字号:
/* * Copyright 2004 original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package org.extremecomponents.tree.tag;import java.util.Collection;import java.util.Iterator;import javax.servlet.jsp.JspException;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;import org.extremecomponents.table.bean.Column;import org.extremecomponents.table.bean.Table;import org.extremecomponents.table.handler.ExportHandler;import org.extremecomponents.table.tag.GenerateColumns;import org.extremecomponents.table.tag.TableTag;import org.extremecomponents.tree.core.TreeModel;import org.extremecomponents.util.ExceptionUtils;/** * @jsp.tag name="treetable" display-name="TreeTag" body-content="JSP" * description="Defines everything related to tree." * * @author Paul Horn */public class TreeTag extends TableTag { private static final long serialVersionUID = -6626881785728133686L; private static Log logger = LogFactory.getLog(TreeTag.class); private Iterator iterator; public String parentAttribute; private String identifier; /** * @jsp.attribute description="The field of the bean holding the * relationship to the parent." required="true" * rtexprvalue="true" * * @return Returns the parentAttribute. */ public String getParentAttribute() { return parentAttribute; } /** * @param parentAttribute * The parentAttribute to set. */ public void setParentAttribute(String parentAttribute) { this.parentAttribute = parentAttribute; } /** * @jsp.attribute description="The attribute of the bean used to identify * this column." required="true" rtexprvalue="true" * * @return Returns the identifier. */ public String getIdentifier() { return identifier; } /** * @param identifier * The identifier to set. */ public void setIdentifier(String identifier) { this.identifier = identifier; } public boolean isIteratingBody() { return getModel().getViewHandler().rowcount() > 0; } /** * Add the Column meta data to the Model */ public void addColumn(Column column) { getModel().getColumnHandler().addColumn(column); } /** * Add a Column value to the Model */ public void addColumnValue(String property, Object value) { getModel().getViewHandler().addColumnValue(property, value, null); } /** * Find out how many rows have been added to the Model. */ public int getRowCount() { return getModel().getViewHandler().rowcount(); } /** * The start of the tag. First fire up the Model and then make a copy of the * table tag attributes to send to the model. */ public int doStartTag() throws JspException { logger.debug("TreeTag.doStartTag()"); try { iterator = null; resolveELExpressions(); Table table = new Table(); setModel(new TreeModel(pageContext)); getModel().getTableHandler().addTable(table); ((TreeModel) getModel()).setParentAttribute(parentAttribute); ((TreeModel) getModel()).setIdentifier(identifier); // load up enough attributes to fire up the config and resource // bundle table.addAttribute(Table.LOCALE, getLocaleObject()); table.addAttribute(Table.RESOURCE_BUNDLE_LOCATION, getResourceBundleLocation()); table.addAttribute(Table.PROPERTIES_LOCATION, getPropertiesLocation()); getModel().getProperties().init(); getModel().getResourceBundle().init(); // load up enough attributes to fire up the ParameterRegistry table.addAttribute(Table.ID, getId()); table.addAttribute(Table.COLLECTION, getCollection()); table.addAttribute(Table.AUTO_INCLUDE_PARAMETERS, getAutoIncludeParameters()); table.addAttribute(Table.SAVE_FILTER_SORT, getSaveFilterSort()); getModel().getRegistry().init(pageContext); table.addAttribute(Table.SCOPE, getScope()); table.addAttribute(Table.ACTION, getAction()); table.addAttribute(Table.STYLE_CLASS, getStyleClass()); table.addAttribute(Table.HEADER_CLASS, getHeaderClass()); table.addAttribute(Table.BORDER, getBorder()); table.addAttribute(Table.CELLPADDING, getCellpadding()); table.addAttribute(Table.CELLSPACING, getCellspacing()); table.addAttribute(Table.ROWS_DISPLAYED, getRowsDisplayed()); table.addAttribute(Table.FILTERABLE, getFilterable()); table.addAttribute(Table.SHOW_PAGINATION, getShowPagination()); table.addAttribute(Table.SHOW_STATUS_BAR, getShowStatusBar()); table.addAttribute(Table.IMAGE_PATH, getImagePath()); table.addAttribute(Table.SORTABLE, getSortable()); table.addAttribute(Table.TITLE, getTitle()); table.addAttribute(Table.STYLE, getStyle()); table.addAttribute(Table.WIDTH, getWidth()); table.addAttribute(Table.TOTAL_TITLE, getTotalTitle()); table.addAttribute(Table.RETRIEVE_ROWS_CALLBACK, getRetrieveRowsCallback()); table.addAttribute(Table.FILTER_ROWS_CALLBACK, getFilterRowsCallback()); table.addAttribute(Table.SORT_ROWS_CALLBACK, getSortRowsCallback()); table.addAttribute(Table.VIEW, getView()); table.addAttribute(Table.INITIAL_ROWS_DISPLAYED, getInitialRowsDisplayed()); table.addAttribute(Table.ROWS_DISPLAYED, getRowsDisplayed()); pageContext.setAttribute("ROWCOUNT", "0"); } catch (Exception e) { throw new JspException("TreeTag.doStartTag() Problem: " + ExceptionUtils.formatStackTrace(e)); } return EVAL_BODY_INCLUDE; } /** * Two things need to be accomplished here. First, need to iterate once over * the columns to load up all the attributes. Second, need to iterate over * the columns as many times as specified by the maxRows attribute so the * columns rows can be resolved. On each iteration over the columns the * current bean in the Collection is passed via the PageContext. */ public int doAfterBody() throws JspException { logger.debug("TreeTag.doAfterBody()"); TreeModel model = (TreeModel) getModel(); try { if (model.getViewHandler().rowcount() == 0) { Collection rows = model.execute(); iterator = rows.iterator(); } } catch (Exception e) { e.printStackTrace(); throw new JspException("TreeTag.doAfterBody() Problem: " + ExceptionUtils.formatStackTrace(e)); } if ((iterator != null) && iterator.hasNext()) { model.getViewHandler().addRow(); Object bean = iterator.next(); getModel().getTableHandler().setCurrentCollectionBean(bean); pageContext.setAttribute(getCollection(), bean); pageContext.setAttribute("ROWCOUNT", "" + getRowCount()); return EVAL_BODY_AGAIN; } else { return SKIP_BODY; } } /** * As a convenience use the EL expression langauge for the columns that need * it. Also execute the Model so that it can do all its processing and build * the table. */ public int doEndTag() throws JspException { logger.debug("TreeTag.doEndTag()"); try { if (!getModel().getColumnHandler().hasMetatData()) { Collection rows = getModel().execute(); GenerateColumns.autoSetColumns(this, rows); } Object output = getModel().getViewHandler().getView().afterBody(getModel()); if (output instanceof String) { pageContext.getOut().println(output); } pageContext.getRequest().setAttribute(ExportHandler.EXPORT_DATA, output); } catch (Exception e) { throw new JspException("TreeTag.doEndTag() Problem: " + ExceptionUtils.formatStackTrace(e)); } getModel().destroy(); return EVAL_PAGE; } public void doFinally() { iterator = null; parentAttribute = null; super.doFinally(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -