Several months ago I mentioned that I was developing classes based on WicketExtensions' DataTable and SortableDataProvider to display arbitrary SQL SELECT result sets, with arbitrary sorting capability built-in.  
My approach is only appropriate for small result sets or for prototyping, as the ResultSet's data is kept in the data provider between page renderings:
  • The developer overrides the method that generates the SQL query string.  If the generated text varies from one postback to the next (or if an event sets a special flag), the data is replaced by a new query to the database. 
  • A general routine handles sorting events (column-header clicks) by delegating to column type's default comparator and the built-in ArrayList sorting capability. 
  • A hook is provided where the developer can specify massaging of the data between download and presentation, e.g. to compute and add a summary row, to insert additional computed columns, or to replace date or number objects by formatted strings (to bypass DataTable's default rendering of these objects). 
(Perhaps someone can adapt some of my ideas to a more general solution that doesn't keep result-set data in the DataProvider between postbacks.) 
My implementation consists of just a few hundred lines of code in four classes, two of which are trivial javabeans.  A few readers of this group expressed interest; what would be the easiest way of sharing?  I suppose I could build a tiny jar file and attach it to an e-mail, but it might be easier to discuss the implementation if I send a few e-mails, each directly containing the source code for one or two classes.  Would that be an appropriate use of this mailing list?

From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Vincent Jenks
Sent: Wednesday, March 15, 2006 9:29 AM
Subject: Re: [Wicket-user] DataView (extentions)

I'd love to see this (along w/ an example or two on usage) ;)

On 3/15/06, Frank Silbermann <[EMAIL PROTECTED] > wrote:

I have come up with my own subclass of DataTable and implementation of IDataProvider to display any arbitrary database java.sql.ResultSet.  The basic idea is that my IDataProvider implementation contains a List of rows, each row consisting of a List of Object.  Also in the implementation is an array of descriptors, one per column, each of which contains the column name and an indicator as to whether I want to be able to sort on that column.  (The column name comes from the ResultSetMetadata; a method is provided to set the sortability flag.)  My implementation of the abstract method to deliver a sequence of rows will delegate to the List.sublist() command from the Java Collections API, and each time the DataTable delivers a sort criteria I apply the Collections.sort() method to my list of rows, passing it a Comparator that delegates to the Comparator of the Object at the relevant column index.  My implementation of IDataProvider can also look at my array of column descriptors and generate a list of IColumn objects (needed to construct the DataTable).

It's actually a bit more complicated than that, because  sometimes the user needs to add one or more summary rows or add computed columns. 

The code is actually quite compact; when I'm finished I'll post it to the list if there is any interest.



-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] On Behalf Of Igor Vaynberg
Tuesday, March 14, 2006 5:21 PM
Subject: Re: [Wicket-user] DataView (extentions)


there is also a DataTable component which wraps DataView+paging+sorting.


On 3/14/06, Vincent Jenks < [EMAIL PROTECTED]> wrote:

I'm using 1.1.1  Are there any plans to whittle down the amount of code it takes to implement paging & sorting?  Has it changed at all in 1.2?  I spent a lot of time w/ ASP.NET (which wicket feels quite similar to) and there's a DataGrid component that has properties to set paging & sorting w/o any extra work.  Something like that would be really convenient.

Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
Wicket-user mailing list

Reply via email to