What I have done is to add a TableDecorator to the <display:table> tag and code it like outlined below. The startRow() and finishRow() methods only get called when displaytag is writing out the html so you can use those method to set a flag (display) to true or false and then check that flag in the getXxx() methods to format the date for sorting or for displaying.
public class ItemsTableDecorator extends TableDecorator {
/**
* A date formatter that allows sorting by date
*/
private Format sortformat;
/**
* A flag to tell the decorator methods when they're being sorted and when they're being
* displayed. Set to true by startRow and false by finishRow
*/
private boolean display = false;
/**
* Create the sortable date format
*/
public void init(PageContext context, Object decorated) {
super.init(context, decorated);
sortformat = new SimpleDateFormat("yyyyMMddHHmmss");
}
/**
* Set the display flag to true - we are outputting to html
*/
public String startRow() {
display = true;
}
/**
* Decorator for the Article Date column
*/
public String getArticledate() {
String date = "";
ItemEntity item = (ItemEntity)this.getCurrentRowObject();
if (display) {
Format dateformat = new SimpleDateFormat(item.getFrequencyformat());
date = dateformat.format(item.getArticledate());
} else {
date = sortformat.format(item.getArticledate());
}
return date;
}
/**
* Turn off the display flag - we've finished outputting to html
*/
public String finishRow() {
display = false;
}
}
Ed!
-----Original Message-----
From: Diego [mailto:[EMAIL PROTECTED]]
Sent: 02 April 2004 13:36
To: [EMAIL PROTECTED]
Subject: [displaytag-user] Sort date column
Hi! I have a table where one of the fields represents data elements. The problem
is that displaytag sorts them as strings and obviously I want it to sort them as
dates. Any workaraound for this?
Thanks in advance
----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.
-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
_______________________________________________
displaytag-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/displaytag-user

