Home » displaytag-1.1.1-src » org » displaytag » tags » [javadoc | source]

    1   /**
    2    * Licensed under the Artistic License; you may not use this file
    3    * except in compliance with the License.
    4    * You may obtain a copy of the License at
    5    *
    6    *      http://displaytag.sourceforge.net/license.html
    7    *
    8    * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
    9    * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
   10    * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
   11    */
   12   package org.displaytag.tags;
   13   
   14   import java.util.List;
   15   import java.util.Map;
   16   
   17   import javax.servlet.jsp.JspException;
   18   import javax.servlet.jsp.tagext.BodyTagSupport;
   19   
   20   import org.displaytag.exception.TagStructureException;
   21   import org.displaytag.properties.MediaTypeEnum;
   22   import org.displaytag.util.MediaUtil;
   23   
   24   
   25   /**
   26    * Display a table footer. Html only, not included in export.
   27    * @author Fabrizio Giustina
   28    * @author rapruitt
   29    * @version $Revision: 1081 $ ($Author: fgiust $)
   30    */
   31   public class TableFooterTag extends BodyTagSupport implements MediaUtil.SupportsMedia
   32   {
   33   
   34       /**
   35        * D1597A17A6.
   36        */
   37       private static final long serialVersionUID = 899149338534L;
   38   
   39       /**
   40        * The media supported attribute.
   41        */
   42       private List supportedMedia;
   43   
   44       /**
   45        * Show the footer as a last table row.
   46        */
   47       private boolean showAsLastRow;
   48   
   49       /**
   50        * @see javax.servlet.jsp.tagext.Tag#doEndTag()
   51        */
   52       public int doEndTag() throws JspException
   53       {
   54           TableTag tableTag = (TableTag) findAncestorWithClass(this, TableTag.class);
   55   
   56           if (tableTag == null)
   57           {
   58               throw new TagStructureException(getClass(), "footer", "table");
   59           }
   60   
   61           MediaTypeEnum currentMediaType = (MediaTypeEnum) this.pageContext.findAttribute(TableTag.PAGE_ATTRIBUTE_MEDIA);
   62           if (currentMediaType != null && !MediaUtil.availableForMedia(this, currentMediaType))
   63           {
   64               return SKIP_BODY;
   65           }
   66   
   67           if (tableTag.isLastIteration())
   68           {
   69               if (getBodyContent() != null)
   70               {
   71                   tableTag.setFooter(getBodyContent().getString());
   72               }
   73           }
   74   
   75           return EVAL_PAGE;
   76       }
   77   
   78       /**
   79        * @see javax.servlet.jsp.tagext.Tag#doStartTag()
   80        */
   81       public int doStartTag() throws JspException
   82       {
   83           TableTag tableTag = (TableTag) findAncestorWithClass(this, TableTag.class);
   84   
   85           if (tableTag == null)
   86           {
   87               throw new TagStructureException(getClass(), "footer", "table");
   88           }
   89   
   90           MediaTypeEnum currentMediaType = (MediaTypeEnum) this.pageContext.findAttribute(TableTag.PAGE_ATTRIBUTE_MEDIA);
   91           if (!MediaUtil.availableForMedia(this, currentMediaType))
   92           {
   93               return SKIP_BODY;
   94           }
   95   
   96           // Run the footer only when all of the cells have been populated
   97           if (tableTag.isLastIteration())
   98           {
   99               if (tableTag.getVarTotals() != null)
  100               {
  101                   Map totals = tableTag.getTotals();
  102                   this.pageContext.setAttribute(tableTag.getVarTotals(), totals);
  103               }
  104               // using int to avoid deprecation error in compilation using j2ee 1.3 (EVAL_BODY_TAG)
  105               return 2;
  106           }
  107   
  108           return SKIP_BODY;
  109       }
  110   
  111       /**
  112        * @see org.displaytag.util.MediaUtil.SupportsMedia#setSupportedMedia(java.util.List)
  113        */
  114       public void setSupportedMedia(List media)
  115       {
  116           this.supportedMedia = media;
  117       }
  118   
  119       /**
  120        * @see org.displaytag.util.MediaUtil.SupportsMedia#getSupportedMedia()
  121        */
  122       public List getSupportedMedia()
  123       {
  124           return this.supportedMedia;
  125       }
  126   
  127       /**
  128        * Tag setter.
  129        * @param media the space delimited list of supported types
  130        */
  131       public void setMedia(String media)
  132       {
  133           MediaUtil.setMedia(this, media);
  134       }
  135   
  136       /**
  137        * @see javax.servlet.jsp.tagext.Tag#release()
  138        */
  139       public void release()
  140       {
  141           this.supportedMedia = null;
  142           this.showAsLastRow = false;
  143           super.release();
  144       }
  145   
  146       /**
  147        * Tag setter.
  148        * @param showAsLastRow the space delimited list of supported types
  149        */
  150       public void setShowAsLastRow(boolean showAsLastRow)
  151       {
  152           this.showAsLastRow = showAsLastRow;
  153       }
  154   }

Home » displaytag-1.1.1-src » org » displaytag » tags » [javadoc | source]