Menu

Sorting on Date in dd-MMM-yyyy format

2006-01-19
2012-10-09
  • Leena Kulkarni

    Leena Kulkarni - 2006-01-19

    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

     
    • Jonathan Gordon

      Jonathan Gordon - 2006-01-19

      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.

       
      • Leena Kulkarni

        Leena Kulkarni - 2006-01-19

        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?

         
        • Jonathan Gordon

          Jonathan Gordon - 2006-01-19

          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.

           
          • Chris Widhelm

            Chris Widhelm - 2006-01-27

            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.

             
          • Leena Kulkarni

            Leena Kulkarni - 2006-01-20

            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.

             

Log in to post a comment.

MongoDB Logo MongoDB