If the date's a string, then the sorting probably won't work right, but that
strictly depends on the date format.  Some date formats will sort
alphabetically into the right order (e.g. yyyy-mm-dd hh:mm:ss.S will sort
properly, as long as the months and days are zero-padded to two characters),
but if you have a date in U.S. format, e.g. November 10, 2005, the sorting
won't work on the date but on the alphabetical order of the string.  You can
use the decorator or JSTL tag to render a proper Date object into the
correct format with the sorting on the date property or use the sortProperty
attribute to sort on something else that would give you the proper sort
order.  In practice, you'd do the first (i.e. use a decorator or tag to
render a date and just sort on that).

Rick Herrick
[EMAIL PROTECTED]

> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:displaytag-user-
> [EMAIL PROTECTED] On Behalf Of fea jabi
> Sent: Thursday, November 10, 2005 8:48 AM
> To: [email protected]
> Subject: Re: [displaytag-user] Column Decorator for Date
> 
> thankyou for your response.
> 
> This worked. But have a question. I am using sorting for this column too.
> 
> I made sure this column data is of type Date for sorting to work right.
> 
> Does this get sorted right I mean the Dates if the column data is String
> type no right!!
> 
> 
> 
> >From: "Rick Herrick" <[EMAIL PROTECTED]>
> >Reply-To: [email protected]
> >To: [email protected]
> >Subject: Re: [displaytag-user] Column Decorator for Date
> >Date: Thu, 10 Nov 2005 08:09:55 -0800 (PST)
> >
> >fea jabi said:
> > > I am having a column which is displaying Dates in the below format.
> > >
> > > Mon Oct 10 00:00:00 EDT 2005
> > >
> > >
> > > But want the format to be in MM/dd/yy format.
> > >
> > > How can this be done?
> > >
> > > Thanks.
> >
> >Create a class that extends ColumnDecorator and implements the decorate()
> >method. I included an example at the bottom of my reply.  Then just apply
> >that to the column you want to format:
> >
> ><display:column property="myDate" decorator="ShortDateDecorator" />
> >
> >Here's the class:
> >
> >public class ShortDateDecorator implements ColumnDecorator
> >{
> >     /**
> >      * Used to format the date object.
> >      */
> >     SimpleDateFormat dateFormat = new SimpleDateFormat("M/d/yyyy");
> >
> >     /**
> >      * transform the given object into a String representation.
> >      * @param columnValue Object
> >      * @return String
> >      */
> >     public final String decorate(Object columnValue)
> >     {
> >         String formattedDate = null;
> >
> >         if (columnValue instanceof Date)
> >         {
> >              formattedDate = dateFormat.format((Date) columnValue);
> >         }
> >         else if (columnValue instanceof String)
> >         {
> >             try
> >             {
> >                  formattedDate =
> >dateFormat.format(dateFormat.parse((String)
> >columnValue));
> >             }
> >             catch (ParseException e)
> >             {
> >                 //
> >             }
> >         }
> >
> >         return formattedDate;
> >     }
> >}
> >
> >
> >
> >--
> >Rick Herrick
> >[EMAIL PROTECTED]
> >
> >I haven't got time for inner peace.
> >
> >Get out of control, but appear under control. It's not bad to alarm other
> >people, though--it's good for them.--Hunter S. Thompson
> >
> >
> >-------------------------------------------------------
> >SF.Net email is sponsored by:
> >Tame your development challenges with Apache's Geronimo App Server.
> >Download
> >it for free - -and be entered to win a 42" plasma tv or your very own
> >Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
> >_______________________________________________
> >displaytag-user mailing list
> >[email protected]
> >https://lists.sourceforge.net/lists/listinfo/displaytag-user
> 
> _________________________________________________________________
> Express yourself instantly with MSN Messenger! Download today - it's FREE!
> http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
> 
> 
> 
> -------------------------------------------------------
> SF.Net email is sponsored by:
> Tame your development challenges with Apache's Geronimo App Server.
> Download
> it for free - -and be entered to win a 42" plasma tv or your very own
> Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
> _______________________________________________
> displaytag-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/displaytag-user


-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
displaytag-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/displaytag-user

Reply via email to