[opencms-dev] Override compareTo Method from CmsJspNavElement

fritz7 deepfritz7 at gmx.net
Mon Aug 25 21:15:48 CEST 2008


Hi!

I have build my own Navigation using CmsJspNavBuilder. Now i would like to sort the list of the CmsJspNavElement's. For this purpose the CmsJspNavElement has already a compareTo Method which could been used by the Comparable Interface.

Now I would like to use my own compareTo Method whlie override the original.

Using the @Override Keyword didn't work...

So what do I have to do?


This the example I tried to use (the original Method):
<%!

   
@Override public int compareTo(Object obj) {

        if (obj == this) {
            return 0;
        }
        if (obj instanceof CmsJspNavElement) {
            float pos = ((CmsJspNavElement)obj).getNavPosition();
            // please note: can't just subtract and cast to int here because of float precision loss
            if (m_position == pos) {
                return 0;
            }
            return (m_position < pos) ? -1 : 1;
        }
        return 0;
    }
%>


there occur several errors:

    
Fehler Unable to compile class for JSP:

An error occurred at line: 332 in the jsp file: /WEB-INF/jsp/offline/system/modules/org.opencms.firstmodule/templates/main.jsp
The method compareTo(Object) of type main_jsp must override a superclass method
329: // Wenn "this = argument" dann muss die Methode 0 (irgendetwas = 0) zurückgeben
330: // Wenn "this > argument" dann muss die Methode irgendetwas > 0 zurückgeben
331:
332: @Override public int compareTo(Object obj) {
333:
334: if (obj == this) {
335: return 0;


An error occurred at line: 337 in the jsp file: /WEB-INF/jsp/offline/system/modules/org.opencms.firstmodule/templates/main.jsp
CmsJspNavElement cannot be resolved to a type
334: if (obj == this) {
335: return 0;
336: }
337: if (obj instanceof CmsJspNavElement) {
338: float pos = ((CmsJspNavElement)obj).getNavPosition();
339: // please note: can't just subtract and cast to int here because of float precision loss
340: if (m_position == pos) {


An error occurred at line: 338 in the jsp file: /WEB-INF/jsp/offline/system/modules/org.opencms.firstmodule/templates/main.jsp
CmsJspNavElement cannot be resolved to a type
335: return 0;
336: }
337: if (obj instanceof CmsJspNavElement) {
338: float pos = ((CmsJspNavElement)obj).getNavPosition();
339: // please note: can't just subtract and cast to int here because of float precision loss
340: if (m_position == pos) {
341: return 0;


etc.


Soo, did I try something very stupid or whats the problem here? My goal ist just to sort the list of the NavElements following my own rules. I extended the NavPos Property to this format XX.XX.XX.XX.. und of course, the original compareTo Method can't deal with that.


Thanks for your help!
-- 
GMX Kostenlose Spiele: Einfach online spielen und Spaß haben mit Pastry Passion!
http://games.entertainment.gmx.net/de/entertainment/games/free/puzzle/6169196



More information about the opencms-dev mailing list