I have a similar problem in that the behavior of SortableDataProvider differs
between systems it's running on. Deploy the same war to dev or test system
and pagination works but in production it doesn't - go figure.

I find that when pagination works there are two calls to size() before the
iterator() call, which has the correct first value, when a navigation link
is requested. When it doesn't work there is only one call to size() and the
following iterator() call sticks at first = 0.

Any insight is greatly appreciated.



Kenny Stainback wrote:
> 
> In the constructor that takes the company id in SortableUserDataProvider,
> you are retrieving all users for the specified company id and assigning
> that to the "users" class-level variable.  But, in the iterator() method,
> you retrieve another subset (page) of users and assign it to the same
> "users" class-level variable.  The size() method would then just return
> the number of records in the subset, but actually needs the total number
> of rows to page.
> 
> Here's an example SortableDataProvider (mostly stolen from the Wicket
> examples) which uses 2 queries... 1 to get the paged number of users and 1
> to get the total count.  Notice there is no need to return all users in
> the system (or in your case, for a specific company), which may be
> problematic from a performance standpoint.  Feedback welcome:
> 
> public class SortableUserDataProvider extends SortableDataProvider{
> 
>       private static final long serialVersionUID = 271688819644192359L;
> 
>     /**
>      * constructor
>      */
>     public SortableUserDataProvider()
>     {
>         // set default sort
>         setSort("firstName", true);
>     }
> 
>     protected IUserService getUserService()
>     {
>         return ((KsxApplication)Application.get())
>               .getUserService();
>     }
> 
>     /**
>      * @see
> org.apache.wicket.markup.repeater.data.IDataProvider#iterator(int, int)
>      */
>     public Iterator iterator(int first, int pageSize)
>     {
>         SortParam sp = getSort();
>         int page = 0;
>         if (first != 0) {
>               page = first / pageSize;
>         }
> 
>         return getUserService().findPage(page, pageSize, sp.getProperty(),
> sp.isAscending()).iterator();
>     }
> 
>     /**
>      * @see org.apache.wicket.markup.repeater.data.IDataProvider#size()
>      */
>     public int size()
>     {
>         return getUserService().findTotalCount();
>     }
> 
>     /**
>      * @see
> org.apache.wicket.markup.repeater.data.IDataProvider#model(java.lang.Object)
>      */
>     public IModel model(Object object)
>     {
>         return new DetachableUserModel((User)object);
>     }
>       
> }
> 

-- 
View this message in context: 
http://www.nabble.com/DefaultDataTable-not-paging-correctly-tp16180335p17528548.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to