|
View:
New views
4 Messages
—
Rating Filter:
Alert me
|
|
|
Facing Issues with velocity sortTool to sort Two java.util.Date TypeHi All,
I am using velocity 1.5 sortTool to sort the
properties of list. I am sorting two date, createdAt and updatedAt both property
of dto are java.util.Date type. I am trying to sort on updatedAt first and if
updatedAt is null then on createdAt. Its working fine if there is some value
in updatedAt, but its not working if updatedAt has null value. Please
help me out of this problem. code sample is attached with this mail.
Thanks & Regards, Ranjeet <tool> <key>sorter</key> <scope>application</scope> <class>org.apache.velocity.tools.generic.SortTool</class> </tool> velocity Code ============ #foreach($obj in $sorter.sort(${campaign.notes}, ["updatedAt:desc", "createdAt:desc"])) $obj.id, $obj.shortText , crreatedAt : $obj.createdAt , updatedAt : $obj.updatedAt <br /> #end DTO implements Comparable<Note> with method private Date createdAt; private Date updatedAt; // and their setter/getter method. public int compareTo(Note other) { //Note other = (Note)o; int returnValue = 0; if (this.getUpdatedAt() != null && other.getUpdatedAt() != null) { returnValue = this.getUpdatedAt().compareTo(other.getUpdatedAt()); if (returnValue == 0){ returnValue = this.getCreatedAt().compareTo(other.getCreatedAt()); } } else { returnValue = this.getCreatedAt().compareTo(other.getCreatedAt()); } return returnValue; }* --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@... For additional commands, e-mail: user-help@... |
|
|
Re: Facing Issues with velocity sortTool to sort Two java.util.Date TypeCould you be more specific about what you mean by "not working"? What
happens? The code sample looks like you are already implementing the search pattern you want. Why not just try: $sorter.sort(${campaign.notes}) On Mon, Apr 20, 2009 at 3:42 AM, Ranjeet <ranjeet.jha@...> wrote: > Hi All, > > I am using velocity 1.5 sortTool to sort the properties of list. I am > sorting two date, createdAt and updatedAt both property of dto are > java.util.Date type. I am trying to sort on updatedAt first and if updatedAt > is null then on createdAt. Its working fine if there is some value > in updatedAt, but its not working if updatedAt has null value. Please help > me out of this problem. code sample is attached with this mail. > > Thanks & Regards, > Ranjeet > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: user-unsubscribe@... > For additional commands, e-mail: user-help@... > --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@... For additional commands, e-mail: user-help@... |
|
|
Re: Facing Issues with velocity sortTool to sort Two java.util.Date TypeHi,
I have a DTO Note.java in which there are some porperty like createdAt and updatedAt of java.util.Date type. I want to sort the order of list by updatedAt and createdAt. When I create the note/entity on that time I set java.util.Date() in createdAt property and not set in updatedAt so updatedAt property is null in db and dto both at very first, when I am going to update the same note/entity on that time I set the java.util.Date in updatedAt property and update the entity then both property becomes not null, means some values in dto and table. Now I want to sort the order of list by updatedAt and createdAt so recent updated record should come on top and want to shwo only recent five records only. If updatedAt and createdAt property is not null then works fine. for example if there is 3 record and 2 note/entity are updated and one is not updated, means in list of 3 dto , 2 dto have values in updatedAt and in one DTO the value in updatedAt is null, in this scenario not sorting and not displaying the records. I mean if any of the updatedAt property is null in dto list then not display the record,. I could not find the solution why this is not displaying while sorting? Thanks & Regards, Ranjeet ----- Original Message ----- From: "Nathan Bubna" <nbubna@...> To: "Velocity Users List" <user@...> Sent: Wednesday, April 22, 2009 11:56 PM Subject: Re: Facing Issues with velocity sortTool to sort Two java.util.Date Type Could you be more specific about what you mean by "not working"? What happens? The code sample looks like you are already implementing the search pattern you want. Why not just try: $sorter.sort(${campaign.notes}) On Mon, Apr 20, 2009 at 3:42 AM, Ranjeet <ranjeet.jha@...> wrote: > Hi All, > > I am using velocity 1.5 sortTool to sort the properties of list. I am > sorting two date, createdAt and updatedAt both property of dto are > java.util.Date type. I am trying to sort on updatedAt first and if > updatedAt > is null then on createdAt. Its working fine if there is some value > in updatedAt, but its not working if updatedAt has null value. Please help > me out of this problem. code sample is attached with this mail. > > Thanks & Regards, > Ranjeet > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: user-unsubscribe@... > For additional commands, e-mail: user-help@... > --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@... For additional commands, e-mail: user-help@... --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@... For additional commands, e-mail: user-help@... |
|
|
Re: Facing Issues with velocity sortTool to sort Two java.util.Date TypeIf there is an exception (like a NullPointerException) during sorting,
then SortTool will return null. The null field is apparently causing an exception. I'm not sure why, but i would guess that it is because the java.util.Date class' compareTo method doesn't like it when you pass in null as an argument. SortTool never calls compareTo on a null object, but it will pass null objects in to compareTo (e.g. myNotNullComparable.compareTo(nullComparable) ). That's the best guess i have for you. You might try subclassing SortTool to right your own sort method that can handle this situation. or just making your Note class comparable and doing $sorter.sort(${notes}). On Thu, Apr 23, 2009 at 6:04 AM, Ranjeet <ranjeet.jha@...> wrote: > Hi, > > I have a DTO Note.java in which there are some porperty like createdAt and > updatedAt of java.util.Date type. I want to sort the order of list by > updatedAt and createdAt. When I create the note/entity on that time I set > java.util.Date() in createdAt property and not set in updatedAt so updatedAt > property is null in db and dto both at very first, when I am going to update > the same note/entity on that time I set the java.util.Date in updatedAt > property and update the entity then both property becomes not null, means > some values in dto and table. Now I want to sort the order of list by > updatedAt and createdAt so recent updated record should come on top and want > to shwo only recent five records only. If updatedAt and createdAt property > is not null then works fine. for example if there is 3 record and 2 > note/entity are updated and one is not updated, means in list of 3 dto , 2 > dto have values in updatedAt and in one DTO the value in updatedAt is null, > in this scenario not sorting and not displaying the records. I mean if any > of the updatedAt property is null in dto list then not display the record,. > I could not find the solution why this is not displaying while sorting? > > > Thanks & Regards, > Ranjeet > > > ----- Original Message ----- From: "Nathan Bubna" <nbubna@...> > To: "Velocity Users List" <user@...> > Sent: Wednesday, April 22, 2009 11:56 PM > Subject: Re: Facing Issues with velocity sortTool to sort Two java.util.Date > Type > > > Could you be more specific about what you mean by "not working"? What > happens? The code sample looks like you are already implementing the > search pattern you want. Why not just try: > > $sorter.sort(${campaign.notes}) > > On Mon, Apr 20, 2009 at 3:42 AM, Ranjeet <ranjeet.jha@...> > wrote: >> >> Hi All, >> >> I am using velocity 1.5 sortTool to sort the properties of list. I am >> sorting two date, createdAt and updatedAt both property of dto are >> java.util.Date type. I am trying to sort on updatedAt first and if >> updatedAt >> is null then on createdAt. Its working fine if there is some value >> in updatedAt, but its not working if updatedAt has null value. Please help >> me out of this problem. code sample is attached with this mail. >> >> Thanks & Regards, >> Ranjeet >> >> >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: user-unsubscribe@... >> For additional commands, e-mail: user-help@... >> > > --------------------------------------------------------------------- > To unsubscribe, e-mail: user-unsubscribe@... > For additional commands, e-mail: user-help@... > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: user-unsubscribe@... > For additional commands, e-mail: user-help@... > > --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@... For additional commands, e-mail: user-help@... |
| Free embeddable forum powered by Nabble | Forum Help |