Rick, Thanks for your response. I tried the same but it's not sorting right. Please see below and suggest what's the mistake?
have an obj Customer Customer has attributes name - String createDate - Date in struts action DateFormat dateFormat = new SimpleDateFormat("MM-dd-yyyy"); custObj1.setCreateDate(dateFormat.parse("7-1-2005")); and created list of cust objects in jsp <display:table name="sessionScope.Form1.custList" id="custRow" requestURI="PrepareAction.do" defaultsort="2" defaultorder="descending" pagesize="6"> ....... ...... <!-- Create Date --> <display:column titleKey="lbl.crdate" sortable="true" > <c:if test="${custRow.createDate != null}" > <fmt:formatDate value="${custRow.createDate}" pattern="MM-dd-yyyy" var="crtDate"/> <c:out value="${crtDate}"/> <!--c:out value="${custRow.createDate}"/--> </c:if> </display:column> .......... ............ </display:table> Thanks. >From: "Rick Herrick" <[EMAIL PROTECTED]> >Reply-To: displaytag-user@lists.sourceforge.net >To: displaytag-user@lists.sourceforge.net >Subject: Re: [displaytag-user] sort not working for Date >Date: Thu, 26 Oct 2006 09:43:47 -0700 (PDT) > >Ed Webb wrote: > > Rick Herrick wrote: > >> Ed Webb wrote: > >> > >>> fea jabi wrote: > >>> > >>>> Thanks for your responses. I appreciate that. > >>>> > >>>> I used the JSTL to format the date. Will it work using that? Do I >have > >>>> to > >>>> use decorator itself? > >>>> > >>> Use the Decorator instead > >> > >> I was actually going to suggest using JSTL for the date format. That > >> lets > >> the sort work on the date object directly (instead of the text > >> representation of the date), but doesn't require extra code. I have an > >> adversion to using decorators. Also, the JSTL date format is easily > >> localizable and easily changeable in a deployed app, whereas changes to > >> code require redeployment or hot-patching of the app. > >> > >> Why would you recommend using the decorator instead? > >> > > From what I remember from the original post, using the JSTL did not > > allow the dates to be sorted chronologically, they were being sorted > > alphabetically. If the JSTL can be used to format the date and > > DisplayTag can correctly sort the Date objects then that'd be the easier > > option. I think that's already been tried and found to not work which is > > why I suggested a Decorator. I suspect I encountered a similar problem > > when I began working with DisplayTag but it was so long ago now that > > I've forgotten. > >The issue with the sorting would depend on the output of the getter. If >the getter puts out a Date object, then sorting would sort >chronologically. If the getter puts out a string containing a formatted >date, then it would sort alphabetically. Just whatever the default >comparator for the data type is. > >You need to treat the tags for the date a bit differently when you're >using JSTL, however. Instead of something like: > ><display:column property="myDate"/> > >Instead do something like (assuming table tag declares uid="item"): > ><display:column sortProperty="myDate" title="Date"> > <fmt:formatDate value="${item.myDate}" pattern="MM/dd/yyyy"/> ></display:column> > >You'll want to play with the pattern and maybe some other attrs on the ><fmt:formatDate> tag. There are also some neat ways to set up >localization with this in conjunction with the <fmt:setLocale> tag, but I >don't really know how to do it. > >-- >Rick Herrick >[EMAIL PROTECTED] > >Proud member of the reality-based community > >Never try to discourage thinking for you are sure to succeed.--Bertrand >Russell > >------------------------------------------------------------------------- >Using Tomcat but need to do more? Need to support web services, security? >Get stuff done quickly with pre-integrated technology to make your job >easier >Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo >http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 >_______________________________________________ >displaytag-user mailing list >displaytag-user@lists.sourceforge.net >https://lists.sourceforge.net/lists/listinfo/displaytag-user _________________________________________________________________ Try Search Survival Kits: Fix up your home and better handle your cash with Live Search! http://imagine-windowslive.com/search/kits/default.aspx?kit=improve&locale=en-US&source=hmtagline ------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 _______________________________________________ displaytag-user mailing list displaytag-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/displaytag-user