Add the additional property "sortProperty" that calls the getTime method on your Date value. Make sure you do a null check on your date and return an appropriate value depending on where you want those elements to display.
Here's how I have it in my .jsp file:
<display:column align="left" title="Batch Date" sortable="true" sortProperty="dateCreatedSortValue" property="dateCreated" />
In this instance, the objects being iterated over have an underlying value that represents the date they were created. The object has a dateCreated bean property, which returns a formatted date string that is suitable for display. Additionally, it has as a dateCreatedSortValue bean property which returns a long value. This is the result of calling the getTime method on the underlying date field.
Hope that helps,
Jonathan.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
We tried this. We wrote our own decorator for the dd-MMM-yyyy format. But when it came to cpecifying it in the sortProperty attribute, we noticed that it is not supported by our version of the jar. [We are using display-tag1.0 jar].
One expert asked us to check if the Date is coming on the page as Date type and not as String, but when we did it [added the Date getters and setters in the FormBean], we do not have these values set properly.
What is wrong in the approach? Thanks for the help in advance.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
We need to sort the rows [ascending and descending fashion alternatively when clicked on up and down arrows in header for the Date column]
For this we need the sorting on Date. Right now it is getting treated as String and we are having Apr coming before Jan.
Can anyone help? Sorry if this is too basic. None of us know much about DisplayTags
Thanks in advance
Add the additional property "sortProperty" that calls the getTime method on your Date value. Make sure you do a null check on your date and return an appropriate value depending on where you want those elements to display.
See the displaytag tag reference sheet for more details:
http://displaytag.sourceforge.net/11/displaytag/tagreference.html
Jonathan.
By any chance, do you have any sample code for this?
We had read this attribute in the tag reference. but did not know how to use this. Is this like specifying the type?
Here's how I have it in my .jsp file:
<display:column align="left" title="Batch Date" sortable="true" sortProperty="dateCreatedSortValue" property="dateCreated" />
In this instance, the objects being iterated over have an underlying value that represents the date they were created. The object has a dateCreated bean property, which returns a formatted date string that is suitable for display. Additionally, it has as a dateCreatedSortValue bean property which returns a long value. This is the result of calling the getTime method on the underlying date field.
Hope that helps,
Jonathan.
How about sorting like this:
<display:column align="left" title="Batch Date" sortable="true" sortProperty="dateCreated.time" property="dateCreated" />
Since there is a getTime method on java.util.Date that returns epoch.
Thanks for the reply.
We tried this. We wrote our own decorator for the dd-MMM-yyyy format. But when it came to cpecifying it in the sortProperty attribute, we noticed that it is not supported by our version of the jar. [We are using display-tag1.0 jar].
One expert asked us to check if the Date is coming on the page as Date type and not as String, but when we did it [added the Date getters and setters in the FormBean], we do not have these values set properly.
What is wrong in the approach? Thanks for the help in advance.