Ok, here is a couple of examples, Asif (using displaytag 1.0b1):

The first example is used to decorate numbers into to decimals. Quantity is just the 
same as BigDecimal, but we have fixed our own implementation. toString on the Quantity 
is just to set the number of decimals and what character to be used as a separator. 
Constants.noOfDecimals() = 2 and Constants.noSeparator() = '.' :
 
import org.displaytag.decorator.ColumnDecorator;
import com.om.condico.util.quantity.Quantity;

public class NumberDecorator implements ColumnDecorator {
    public final String decorate(Object columnValue) {
        String value = "0";

        if (columnValue==null)
            return null;

        if (columnValue instanceof Double) {
            if (((Double)columnValue).doubleValue() == 0) {
                return null;
            }
            value = ((Double) columnValue).toString();
        }
        else if (columnValue instanceof Float) {
            if (((Float)columnValue).floatValue() == 0) {
                return null;
            }
            value = ((Float) columnValue).toString();
        }

        Quantity q = new Quantity(value);

        String retValue = String.valueOf(q.toString(Constants.noOfDecimals(), 
Constants.noSeparator()));

        return retValue;
    }
}
----
and the toString function:

public String toString(int decimalPlaces, char separator) {
                String str = this.getAmount().setScale(decimalPlaces, 
BigDecimal.ROUND_HALF_UP).toString();
                return insert1000Separator(str, separator);
    }
----

It is called by:

<display:column title="Trans.Price" property="price" align="right" sort="true" 
headerClass="sortable" width="10%" decorator="com.somestuffhere.NumberDecorator"/>

-------------

The second example decorates a column with values either true or false to be Buy or 
Sell:

import org.displaytag.decorator.ColumnDecorator;
import org.apache.struts.util.MessageResources;
import org.apache.log4j.Logger;

import java.lang.Boolean;

public class BuySellDecorator implements ColumnDecorator {

    public static MessageResources messages = 
MessageResources.getMessageResources("ApplicationResources");
    String tempBuy = messages.getMessage("web.delivery.buy.column");
    String tempSell = messages.getMessage("web.delivery.sell.column");

    public final String decorate(Object columnValue) {
        if (((Boolean) columnValue).booleanValue())
            return tempBuy;
        else
            return tempSell;
    }
}

-------
If the columnValue is true, it returns the string "Buy" defined in the messageResource 
file. Otherwise, it returns the string "Sell".

Does this makes more sense, Asif?

Hope this helps you a bit.

Cheers,
Bard

----- Original Message -----
From: Asif Rashid <[EMAIL PROTECTED]>
Date: Thu, 23 Oct 2003 12:31:38 -0400
To: "'[EMAIL PROTECTED]'" <[EMAIL PROTECTED]>
Subject: RE: [displaytag-user] RE: displaytag-user digest

> Thanks Rajat for sending code example, but I am looking for Column Decorator
> example. Also it look like from JavaDoc that now they have replaced this
> approach with using Interface. 
> 
> Asif 
> 
> 
> -----Original Message-----
> From: Rajat Pandit [mailto:[EMAIL PROTECTED] 
> Sent: Thursday, October 23, 2003 12:59 AM
> To: [EMAIL PROTECTED]
> Subject: [displaytag-user] RE: displaytag-user digest
> 
> 
> You can do that making ur own class by extending the TableDecorators class.
> Here is the sample code. It took me a long time to figure that out. I might
> have not looked hard enough, but the best way that I personlly think is to
> download the src code, compile it on ur machine and run javadoc on it.
> package com.hedging.decorators;
> 
> import org.displaytag.decorator.TableDecorator;
> import com.hedging.Transaction;
> /**
>  * Created @ Viraj Solutions (I2I)
>  * Date: Oct 5, 2003
>  * Time: 5:39:32 AM
>  * Copyright reserved 2001-2003
>  */
> public class TransactionDecorator extends TableDecorator {
> 
>     String[] call = new String[2];
> 
>     public TransactionDecorator() {
>         super();
>         /**
>          * We shall increment the index
>          * value to get the actual value
>          * of what has to be done.
>          * 1: Selling Call
>          * 2: Buying Call
>          */
>         this.call[0] = "Selling Call";
>         this.call[1] = "Buying Call";
>     }
> 
>     public String getType() {
> 
>        /** this is where the magic happens!! 
>         * Transaction object (ArrayLIst) is the object 
>         * that I am using to render the table
>         */
>         byte type = ((Transaction)this.getCurrentRowObject()).getType();
>         return this.call[(type - 1)];
>     }
> 
> 
> }
> 
> 
> Hope this helps, to let me know if you need any help!
> 
> Great work matt!!!
> 
> 
> --__--__--
> 
> Message: 3
> From: Asif Rashid <[EMAIL PROTECTED]>
> To: "'[EMAIL PROTECTED]'"
>        <[EMAIL PROTECTED]>
> Date: Wed, 22 Oct 2003 19:10:20 -0400
> Subject: [displaytag-user] Column decorator
> Reply-To: [EMAIL PROTECTED]
> 
> Is there any example code available which shows how to develop column
> decorator?
> 
> Asif 
> 
> -----Original Message-----
> 
> 
> 
> -------------------------------------------------------
> This SF.net email is sponsored by: The SF.net Donation Program. Do you like
> what SourceForge.net is doing for the Open Source Community?  Make a
> contribution, and help us add new features and functionality. Click here:
> http://sourceforge.net/donate/
> _______________________________________________
> displaytag-user mailing list [EMAIL PROTECTED]
> https://lists.sourceforge.net/lists/listinfo/displaytag-user
> 
> 
> -------------------------------------------------------
> This SF.net email is sponsored by: The SF.net Donation Program.
> Do you like what SourceForge.net is doing for the Open
> Source Community?  Make a contribution, and help us add new
> features and functionality. Click here: http://sourceforge.net/donate/
> _______________________________________________
> displaytag-user mailing list
> [EMAIL PROTECTED]
> https://lists.sourceforge.net/lists/listinfo/displaytag-user

-- 
___________________________________________________
OperaMail free e-mail - http://www.operamail.com
OperaMail Premium - 28MB, POP3, more! US$29.99/year

Powered by Outblaze


-------------------------------------------------------
This SF.net email is sponsored by: The SF.net Donation Program.
Do you like what SourceForge.net is doing for the Open
Source Community?  Make a contribution, and help us add new
features and functionality. Click here: http://sourceforge.net/donate/
_______________________________________________
displaytag-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/displaytag-user

Reply via email to