The DataTable in
Wicket Extensions allows for both paging and sorting. The API provides a partial implementation of IDataProvider, i.e. SortableDataProvider,
which you can extend – or you can create your own from scratch. There are classes used SortableDataProvider
and also available for your own implementations to allow you to record the
sorting requests which arrive each time the user clicks the heading of a sortable column in the DataTable.
The IDataProvider
method “Iterator iterator(int
first, int count)” -- which you must implement
-- requests one page worth of data rows, specifying where to begin among the
set of all rows, and how many are needed for the current page. It is up to the implementer to ensure that
the rows returned are sorted according to the history of sort requests.
(Presumably, your most recent request
dictates the primary sort level, the previous sort
request would be the secondary sort level, and so on. For example, if the user clicked the header
for first-name and then the header for last-name, the list would be sorted by
last-name, but among people with the same last-name they would appear in
first-name order.)
I believe the creators of DataTable assumed that in the usual case, every invocation
of IDataProvider.Iterator(first, count) would result
in a new request of rows from the database, and the accumulated sort criteria would
be used to build the SQL “ORDER BY” clause. This approach avoids burdening the session
storage, but requires lots of database calls.
It also requires complex custom code to generate the SQL query command taking
into account both the required ORDER BY clause and also to select the proper
subset of rows needed for that page only.
I suppose if you wrapped the ResultSet in a pageable RowSet and kept that RowSet in
session storage, then until the sorting order changed you could use the same RowSet each time a new page is requested. If the RowSet
caches the data, then the RowSet will be a huge
object in your session storage. If you
find a RowSet implementation which reconnects to the
database for each subset of rows you request, that might simplify your code
without burdening session storage. (Of
course, if your RowSet maintained a connection to the
database, you’d be tying up a DBConnection –
not a good idea.)
My problem is to display mostly small
result sets containing not raw data but rather statistics, which may be
time-consuming for the database to compute.
I have about fifty different SQL select queries (not counting variations
in the WHERE clause according to parameters chosen by the user). Usually, these results must be presented in
tables with sortable columns. This is not an e-commerce application;
rather, it provides information to a small group of process engineers. With few users and small result sets, I am
not so worried about session storage. With
about fifty different DataTables to present -- and I’m
not sure we have the _right_ set
of queries, either -- I _am_
greatly concerned about flexibility and ease of programming.
Therefore, I have chosen to allow the
table’s data to remain in session storage, re-sorted in memory whenever
the user requests, and replaced with new data when the user changes the values
of request parameters. The data does not
leave session storage until the page containing it expires -- this is clearly
not a general approach for every kind of production system. The main advantage is that all I have to do
for each table is override the method that generates the SQL SELECT query
string, and I can display the results in a DataTable easily
configured for sorting and/or paging.
(Only a very few of my DataTables are large
enough to require paging.)
When I’m finished, I’ll post
my code; even if it’s not suitable for most production applications my
classes might serve as a useful prototyping tool.
-----Original Message-----
From:
[EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Igor Vaynberg
Sent: Wednesday, March 15, 2006
10:59 AM
To:
[email protected]
Subject: Re: [Wicket-user]
DataView (extentions)
I cant speak for Frank's implementation, but when the
IDataProvider is implemented correctly you only retrieve the window of data
that will be rendered for this request and hold none of it in session. so the
performance of the datatable component itself should be great.
-Igor
On 3/15/06, Mats Norén <[EMAIL PROTECTED]> wrote:
That would be great!
btw, how is the performance with large resultsets?
On 3/15/06, Frank Silbermann <[EMAIL PROTECTED]>
wrote:
>
>
>
> The DataTable in Wicket Extensions 1.1 handles paging and sorting, but you
> must build a custom IDataProvider that accumulates the sorting
instructions
> from the DataTable and provides sorted subsets of the data when requested
by
> the DataTable (which handles the actual paging display).
>
>
>
> DataTable and supporting classes have been greatly refactored in Wicket
> Extensions 1.2 to give the user much more flexibility in the set of features
> desired. The API changes will break Wicket 1.1 programs, so if
you need to
> subclass anything to modify its behavior, I would suggest going to Wicket
> 1.2 now. Otherwise, you can upgrade fairly easily at any time
by replacing
> Wicket 1.1 DataTable with Wicket 1.2 DefaultDataTable. Wicket
1.2 DataTable
> is more flexible but less complete; DefaultDataTable subclasses it to
> provide defaults which make it behave like the Wicket 1.1 DataTable.
>
>
>
> 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 (and a work in progress),
> because I have complicated the above mechanisms to deal with the
possibility
> of a summary row at the end, and when rows are requested, the query string
> will be recalculated based on form data -- and if it has changed since the
> last request then the data will be refreshed from the database and the
> current page set back to 1.
>
>
>
> 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
> Sent: Tuesday, March 14, 2006 5:21 PM
> To: [email protected]
> Subject: Re: [Wicket-user] DataView (extentions)
>
>
>
> there is also a DataTable component which wraps DataView+paging+sorting.
>
> -Igor
>
>
>
>
> 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.
>
>
>
>
>
> On 3/14/06, Igor Vaynberg < [EMAIL PROTECTED]>
wrote:
>
> are you using 1.1 ? or 1.2 ?
> there used to be a constructor that took model in 1.1 i think.
the model
> object must be of type IDataProvider.
>
>
>
>
> -Igor
>
>
>
>
> On 3/14/06, Vincent Jenks <[EMAIL PROTECTED]>
wrote:
>
> Sorry, I didn't mention that the List is wrapped in a detached model....so
> it's an IModel, not List in the constructor.
>
>
>
>
>
> On 3/14/06, Igor Vaynberg < [EMAIL PROTECTED]>
wrote:
>
> yes DataView works with IDataProvider instead of list. not sure why you
> didnt get a compile error since there is no (String,List) constructor.
>
>
> there are examples of dataview and datatable under
> wicket-examples/repeaters
>
> -Igor
>
>
>
>
>
> On 3/14/06, Vincent Jenks < [EMAIL PROTECTED]>
wrote:
>
> So, I'm trying to use a DataView so I can page a collection of objects
> from a session bean.
>
> I create the List collection (loadingModel) and pass it into
the DataView:
>
> DataView productsDataView = new
DataView("productsDataView", loadingModel)
>
> ...but I'm getting an exception at runtime:
>
> "Caused by: java.lang.ClassCastException:
java.util.ArrayList"
>
> I assume then, it's not like the ListView in that it will not
take a
> List directly? Or, have I done something wrong?
>
> Thanks!
>
>
>
>
>
>
>
>
>
>
>
>
>
-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmdlnk&kid0944&bid$1720&dat1642
_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user