Home » displaytag-1.1.1-src » org » displaytag » sample » decorators » [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.sample.decorators;
   13   
   14   import java.text.DecimalFormat;
   15   
   16   import org.apache.commons.lang.time.FastDateFormat;
   17   import org.displaytag.decorator.TableDecorator;
   18   import org.displaytag.sample.ListObject;
   19   
   20   
   21   /**
   22    * This class is a decorator of the TestObjects that we keep in our List. This class provides a number of methods for
   23    * formatting data, creating dynamic links, and exercising some aspects of the display:table API functionality.
   24    * @author epesh
   25    * @author Fabrizio Giustina
   26    * @version $Revision$ ($Author$)
   27    */
   28   public class Wrapper extends TableDecorator
   29   {
   30   
   31       /**
   32        * FastDateFormat used to format dates in getDate().
   33        */
   34       private FastDateFormat dateFormat;
   35   
   36       /**
   37        * DecimalFormat used to format money in getMoney().
   38        */
   39       private DecimalFormat moneyFormat;
   40   
   41       /**
   42        * Creates a new Wrapper decorator who's job is to reformat some of the data located in our TestObject's.
   43        */
   44       public Wrapper()
   45       {
   46           super();
   47   
   48           // Formats for displaying dates and money.
   49   
   50           this.dateFormat = FastDateFormat.getInstance("MM/dd/yy"); //$NON-NLS-1$
   51           this.moneyFormat = new DecimalFormat("$ #,###,###.00"); //$NON-NLS-1$
   52       }
   53   
   54       /**
   55        * Test method which always returns a null value.
   56        * @return <code>null</code>
   57        */
   58       public String getNullValue()
   59       {
   60           return null;
   61       }
   62   
   63       /**
   64        * Returns the date as a String in MM/dd/yy format.
   65        * @return formatted date
   66        */
   67       public String getDate()
   68       {
   69           return this.dateFormat.format(((ListObject) this.getCurrentRowObject()).getDate());
   70       }
   71   
   72       /**
   73        * Returns the money as a String in $ #,###,###.00 format.
   74        * @return String
   75        */
   76       public String getMoney()
   77       {
   78           return this.moneyFormat.format(((ListObject) this.getCurrentRowObject()).getMoney());
   79       }
   80   
   81       /**
   82        * Returns the TestObject's ID as a hyperlink that the person can click on and "drill down" for more details.
   83        * @return String
   84        */
   85       public String getLink1()
   86       {
   87           ListObject object = (ListObject) getCurrentRowObject();
   88           int index = getListIndex();
   89   
   90           return "<a href=\"details.jsp?index=" //$NON-NLS-1$
   91               + index
   92               + "\">" //$NON-NLS-1$
   93               + object.getId()
   94               + "</a>"; //$NON-NLS-1$
   95       }
   96   
   97       /**
   98        * Returns an "action bar" of sorts that allow the user to perform various actions on the TestObject based on it's
   99        * id.
  100        * @return String
  101        */
  102       public String getLink2()
  103       {
  104           ListObject object = (ListObject) getCurrentRowObject();
  105           int id = object.getId();
  106   
  107           return "<a href=\"details.jsp?id=" //$NON-NLS-1$
  108               + id
  109               + "&amp;action=view\">View</a> | " //$NON-NLS-1$
  110               + "<a href=\"details.jsp?id=" //$NON-NLS-1$
  111               + id
  112               + "&amp;action=edit\">Edit</a> | " //$NON-NLS-1$
  113               + "<a href=\"details.jsp?id=" //$NON-NLS-1$
  114               + id
  115               + "&amp;action=delete\">Delete</a>"; //$NON-NLS-1$
  116       }
  117   }

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