how to write this code in jsp scriplet

in the jsp scriplet if i write like this i am getting the exception

 Collections.sort(viewChargesList, new Comparator() {
            public int compare(Object o1, Object o2) {
                 return ((String)o1).compareTo((String)o2);
            }
       });

can i write this   public int compare(Object o1, Object o2) function in jsp scriplet or should i use <%! %>
LVL 20
chaitu chaituAsked:
Who is Participating?
 
TimYatesCommented:
instead of

                 return ((String)o1).compareTo((String)o2);

you will need:

                 return ((HouseDocumentCharges)o1).chargeid.compareTo( ((HouseDocumentCharges)o2).chargeid );

then...
0
 
chaitu chaituAuthor Commented:
05/04/11 19:16:19 java.lang.ClassCastException
05/04/11 19:16:19       at _etrans._ETBBCANCharges$1.compare(_ETBBCANCharges.java:209)
05/04/11 19:16:19       at java.util.Arrays.mergeSort(Arrays.java:1278)
05/04/11 19:16:19       at java.util.Arrays.sort(Arrays.java:1219)
05/04/11 19:16:19       at java.util.Collections.sort(Collections.java:155)
05/04/11 19:16:19       at _etrans._ETBBCANCharges._jspService(_ETBBCANCharges.java:207)
05/04/11 19:16:19       at com.orionserver.http.OrionHttpJspPage.service(OrionHttpJspPage.java:56)
05/04/11 19:16:19       at oracle.jsp.runtimev2.JspPageTable.compileAndServe(JspPageTable.java:567)
05/04/11 19:16:19       at oracle.jsp.runtimev2.JspPageTable.service(JspPageTable.java:302)
05/04/11 19:16:19       at oracle.jsp.runtimev2.JspServlet.internalService(JspServlet.java:509)
05/04/11 19:16:19       at oracle.jsp.runtimev2.JspServlet.service(JspServlet.java:413)
05/04/11 19:16:19       at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
05/04/11 19:16:19       at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:765)
05/04/11 19:16:19       at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:317)
05/04/11 19:16:19       at com.evermind.server.http.ServletRequestDispatcher.forward(ServletRequestDispatcher.java:220)
05/04/11 19:16:19       at com.foursoft.etrans.servlets.common.ETBreakBulkController.doDispatcher(ETBreakBulkController.java:2093)
05/04/11 19:16:19       at com.foursoft.etrans.servlets.common.ETBreakBulkController.handleDispatching(ETBreakBulkController.java:314)
05/04/11 19:16:19       at com.foursoft.etrans.servlets.common.ETBreakBulkController.doPost(ETBreakBulkController.java:245)
05/04/11 19:16:19       at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
05/04/11 19:16:19       at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
05/04/11 19:16:19       at com.evermind.server.http.ResourceFilterChain.doFilter(ResourceFilterChain.java:65)
05/04/11 19:16:19       at com.foursoft.etrans.common.filter.CredentialFilter.doFilter(CredentialFilter.java:116)
05/04/11 19:16:19       at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:604)
05/04/11 19:16:19       at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:317)
05/04/11 19:16:19       at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:790)
05/04/11 19:16:19       at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:270)
05/04/11 19:16:19       at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:112)
05/04/11 19:16:19       at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:186)
05/04/11 19:16:19       at java.lang.Thread.run(Thread.java:534)
0
 
TimYatesCommented:
That will work, but you are casting o1 and o2 to strings, and your list doesn't contain strings...

that's why you're getting the error...
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
chaitu chaituAuthor Commented:
viewChargesList contains arraylist of HouseDocumentCharges object;in that chargeid,chargedesc,paymentmode variables are there;chargeid is string;

i want to sort out the chargeid's;
0
 
chaitu chaituAuthor Commented:
thanks tim
0
 
TimYatesCommented:
:-)

Good luck!!

Tim
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.