Assuming that the database query depends upon whatever page-component selections prompted the post-back, both “int IDataProvider.size()” and “Iterator IDataProvider.iterator(first,count)”  require information that can only be gotten by a database query.:

 

Therefore, for each post-back, I’ll need to query the database before _either_ of these methods return.

 

If both methods query the database independently, intervening CRUD operations may cause them to return inconsistent results (a size that is too small or too large).  I can and should retrieve both the rows and their number with a single query.  The question is where I should do this.

 

My present implementation retrieves the ResultSet when iterator(first,count) is called, setting a size variable that the size() method relies upon. 

MY PROBLEM is that I’m seeing an inconsistent number of rows displayed for the same query.  It seems to depend upon how large the previous query’s results were.

 

If the value of “count” in “Iterator IDataProvider.iterate(first,count)” depends upon the results returned by “int IDataProvider.size()”  that would explain my problem, because the value of “count” would have been based on obsolete information (it would be based on the previous query).  I am wondering whether this is the cause of my problem.

 

If so, I would ask _which_ framework method _should_ trigger the retrieval of database information needed by both IDataProvider methods?  If I knew which of the two methods were called first – I could put the database query there.  Or, perhaps the database query should be triggered by some other framework method which is called before either of them.

 

What are my options?

 

 

.

 

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Igor Vaynberg
Sent: Tuesday, April 04, 2006 3:56 PM
To: wicket-user@lists.sourceforge.net
Subject: Re: [Wicket-user] ?Contract for "Iterator IDataProvider.iterator(int first, int count)" ???

 

the iterator() and size() are not meant to be used "together" and there is no, nor ever be, a contract that guarantees any ordering of invocations between these two methods.

size() is meant to return the total number of rows

iterator() is used to return a window that will be displayed

those are the only contracts.

what exactly is the problem?

-Igor

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

I have a question about the intended use of the DataTable components provided in Wicket Extensions.  The DataTable relies upon an IDataProvider to provide the data.  To do this, we implement:

"Iterator iterate(first, count)"

Lacking any advice to the contrary, I assumed that this is the method which would retrieve data from the database, but this does not seem to be working well for me.

My database query is parameterized based on page-component model values, and these may change with each rendering. My problem is that when one rendering presents a short data set, on the next rendering the DataTable is not always requesting all of the rows.  The "count" seems to be affected by the number of rows returned by the previous rendering.

I suspect this is because my implementation of  "int DataProvider.size()" assumes that it will be called _after_ "Iterator iterate(first, count)" pulls down the data – so it's always one rendering behind.

Should I give the "int IDataProvider.size()" method the responsibility for figuring out the query string and going to the database?  (How else would it be able to tell the DataProvider how many rows to request?)

 

 

Reply via email to