i am not aware of anything like that out there right now so you will have to roll your own. the dataprovider and sortstatelocator are just interfaces so they should stay out of your way.

as far as if this is a good approach or not, what you have to keep in mind is that this list will be held in session until the page expires. if you can live with that then its not a bad way to go.

-Igor


On 2/8/06, Frank Silbermann <[EMAIL PROTECTED]> wrote:

I'd like to implement my DataProvider / SortStateLocator in a general way that doesn't need to be re-done every time I display a different database query in a sortable DataTable.

 

Now, I realize that I could use my SortState to define the ORDER BY in my sql query, and refresh the query every time the SortState changes, but with small result sets I'm thinking of sorting the results in memory.  (Is this a bad idea?)

 

Suppose I use a java.util.ArrayList to represent the results from my sql resultSet.  Rather than making the list element type specific to a single SELECT query, I would want to make the element type more generic – e.g. an arbitrary javabean.

 

To support sortable column-headers in the DataTable, I could sort the list using:

 

static void java.util.Collections.sort(List <T> list, Comparator <? super T> c )

 

but to do that I would have to have a java.util.Comparator for every sortable column, and I really do not want to hand code these for every database query I display.  I should be able to write a general purpose Comparator class that is constructed using a String for the property (column) name, and let it defer to whatever built-in comparator is implemented by that property's data type.

 

Unless someone already provides this kind of functionality in a nice way, I'm thinking of using a HashList for each result in the resultset, and writing my Comparator to:  

  • select the corresponding column values of the two results by property name,
  • cast one of them to java.util.Comparable, and then
  • call comparable.compareTo(Object o) on it.

 

I'd have more type-safety in the rest of my program if I could use an arbitrary javabean to represent a single result from a ResultSet rather than a HashList, but that would require more use of reflection in my comparator to access the property by name.  Compounding things, if I used standard javabean conventions I'd have to convert my lowercase property name to a getProperty accessor (capitalizing the first letter and prefixing "get").

 

That's more work than is worth for a single application program, but I wonder whether an existing API would make things easier (hence my original question).

 

/Frank

 

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] On Behalf Of Igor Vaynberg
Sent: Tuesday, February 07, 2006 3:15 PM
To: [email protected]
Subject: Re: [Wicket-user] reflection question

 

not really sure what you are trying to achieve with all that below.

also you dont need to extend SortableDataProvider, you can use any dataprovider that implements ISortStateLocator.

-Igor

On 2/7/06, Frank Silbermann < [EMAIL PROTECTED]> wrote:


I'm looking at the DataView and DataTable of Wicket Extensions.  To
provide columnheader links that cause sorting, we must implement a
subclass of SortableDataProvider.

To implement a SortableDataProvider it would be really nice to have an
operation that takes in two arbitrary objects and a string (Object o1,
Object o2, String propertyName) such that:

(a) if both objects o1 and o2 have properties named by the input
propertyName string, and

(b) if these properties happen to be of the same type -- a type which
implements the Comparable interface,

(c) then the two properties named by the string are compared and the
results returned.

(If either object lacks the named property, or the corresponding
properties are not of the same type, or the type does not implement
Comparable -- then I suppose an exception can be thrown).

I probably could implement such an operation using reflection, but
unfortunately, this would require work.  Does anyone know of an existing
implementation of this kind of functionality that I could re-use --
either within the Wicket framework or elsewhere?

/Frank


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmdlnk&kid3432&bid#0486&dat1642
_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user

 


Reply via email to