cancel
Showing results for 
Search instead for 
Did you mean: 

About display

terry
Champ in-the-making
Champ in-the-making
Hi,

I wrote following codes in my index.jsp:
<c:forEach items="${pr:getPressReleases(pageContext)}" var="pressRelease">
    <h2 class="headline">
      <jsp:element name="a">
        <jsp:attribute name="href"><cSmiley Surprisedut value="${pressRelease.href}"/></jsp:attribute>
   <jsp:body><cSmiley Surprisedut value="${pressRelease.title}"/></jsp:body>
      </jsp:element>
    </h2>
    <p class="date"><fmt:formatDate value="${pressRelease.launchDate}" dateStyle="long"/></p>
    <p class="abstract"><cSmiley Surprisedut value="${pressRelease.abstract}"/></p>
  </c:forEach>


And the browse display my newses  unorderly.
But I want to display the news's title order by the launchDate desc, how I to do ?
6 REPLIES 6

arielb
Champ in-the-making
Champ in-the-making
you can modify the implementation of getPressReleases (in Util.java) to sort the collection before returning it.

terry
Champ in-the-making
Champ in-the-making
you can modify the implementation of getPressReleases (in Util.java) to sort the collection before returning it.



bu how to I do in detail???
thank you

arielb
Champ in-the-making
Champ in-the-making
at the end of getPressReleases in Util.java add:


Collections.sort(result, new Comparator() {
    public int compare(PressReleaseBean prb1, PressReleaseBean prb2) {
           return prb1.getLaunchDate().compare(prb2.getLaunchDate());
    }
});

see http://java.sun.com/j2se/1.5.0/docs/api/java/util/Collections.html
for more information on how to sort lists.

terry
Champ in-the-making
Champ in-the-making
at the end of getPressReleases in Util.java add:


Collections.sort(result, new Comparator() {
    public int compare(PressReleaseBean prb1, PressReleaseBean prb2) {
           return prb1.getLaunchDate().compare(prb2.getLaunchDate());
    }
});

see http://java.sun.com/j2se/1.5.0/docs/api/java/util/Collections.html
for more information on how to sort lists.



I do it follow your way,but appear two error:

G:\noviweb>javac Util.java
Util.java:56: <cryptonym org.alfresco.web.pr.Util$1>not abstract,and not cover with java.util
.abstract method of Comparator  compare(java.lang.Object,java.lang.Object)
    public int compare(PressReleaseBean prb1, PressReleaseBean prb2) {
               ^
Util.java:57: not find symbol
symbol: method compare(java.util.Date)
location: class java.util.Date
           return prb1.getLaunchDate().compare(prb2.getLaunchDate());
                                    ^
advert: want to know particular information,please use -Xlint:unchecked afresh javac。
2 errors

arielb
Champ in-the-making
Champ in-the-making
the method on Date is compareTo, not compare.  my mistake.

what version of the jdk are you using?  the code i'm providing is for jdk1.5.

if you are using an older jdk this should work.



Collections.sort(result, new Comparator() {
    public int compare(Object o1, Object o2) {
           return ((PressReleaseBean)o1).getLaunchDate().compareTo(((PressReleaseBean)o2).getLaunchDate());
    }
});

terry
Champ in-the-making
Champ in-the-making
the method on Date is compareTo, not compare.  my mistake.

what version of the jdk are you using?  the code i'm providing is for jdk1.5.

if you are using an older jdk this should work.



Collections.sort(result, new Comparator() {
    public int compare(Object o1, Object o2) {
           return ((PressReleaseBean)o1).getLaunchDate().compareTo(((PressReleaseBean)o2).getLaunchDate());
    }
});




i posted you a private message.please see it,thank you.
Getting started

Tags


Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.