Thanks Igor and Doug,
I'll check things out when the boss agrees
bbrrr ...

On Fri, Apr 25, 2008 at 12:39 AM, Doug Donohoe <[EMAIL PROTECTED]> wrote:

>
> This may help.  I am moving my DD Poker site to wicket and implemented an
> IDataProvider around my database service as follows:
>
> private class HistoryData implements IDataProvider
>    {
>        private static final long serialVersionUID = 42L;
>
>        private PokerUser user;
>        private int count;
>
>        private HistoryData(PokerUser user)
>        {
>            this.user = user;
>            count =
> histService.getAllTournamentHistoriesForProfileCount(user.getId());
>        }
>
>        @SuppressWarnings({"RawUseOfParameterizedType"})
>        public Iterator iterator(int first, int pagesize)
>        {
>            return
> histService.getAllTournamentHistoriesForProfile(user.getId(), count,
> first,
> pagesize).iterator();
>        }
>
>        public int size()
>        {
>            return count;
>        }
>
>        public boolean isEmpty()
>        {
>            return count == 0;
>        }
>
>        public IModel model(Object object)
>        {
>            return new CompoundPropertyModel(new EntityModel(object));
>        }
>
>        public void detach()
>        {
>        }
>    }
>
> Where EntityModel is:
>
> public class EntityModel extends CompoundPropertyModel
> {
>    private static final long serialVersionUID = 42L;
>
>    /**
>     * Constructor
>     *
>     * @param object The model object, which may or may not implement
> IModel
>     */
>    public EntityModel(Object object)
>    {
>        super(new NonLoadableDetachableModel(object));
>    }
> }
>
> and NonLoadableDetachableModel is
>
> public class NonLoadableDetachableModel extends LoadableDetachableModel
> {
>    private static final long serialVersionUID = 42L;
>
>    public NonLoadableDetachableModel(Object model)
>    {
>        super(model);
>    }
>
>    @Override
>    protected Object load()
>    {
>        throw new UnsupportedOperationException("load should never be
> called");
>    }
> }
>
> I created this last class because my pages are read-only and the result
> set
> is always fetched through the service.  I didn't want to have my (JPA
> based)
> entities being serialized.
>
> The HistoryData class worked great with the base DataView class in Wicket.
>
> Note that I drew a lot of inspiration from:
>
> http://wicketstuff.org/wicket13/repeater/
>
> and digging around in the source.
>
> I don't know if this will help you or not - hopefully so!
>
> -Doug
>
>
> Eyal Golan wrote:
> >
> > Hi,
> > Can anyone give me an explanation about paging with DetachableModel?
> >
> > My problem:
> > We have records in the DB that can be a-lot.
> > We also filter them sometimes.
> >
> > someone in the company created a non-standard paging.
> > He doesn't use the Wicket's paging.
> >
> > The iterator method of the DataProvider he created returns only the
> number
> > of elements that should be displayed in the current page.
> > Eg. suppose we decided we show 20 records per page.
> > The DataProvider keeps track on which page we're at.
> > Then he calculates the indexes of records.
> > It's done in getVisibleTickets() method.
> > int fromIndex = (currentPage - 1) * (ticketsPerPage);
> > int toIndex = ticketsPerPage;
> >
> > And then he asks the DB for the records in this range (with the filter).
> > This is the size() method:
> >     public int size() {
> >         if ((visibleTickets == null) || (update)) {
> >             getVisibleTickets();
> >         }
> >         return visibleTickets.size();
> >     }
> >
> > OK, I hope i was clear enough.
> > I know that it might be done using Wicket's library.
> > Can anyone explain?
> >
> > Thanks
> > --
> > Eyal Golan
> > [EMAIL PROTECTED]
> >
> > Visit: http://jvdrums.sourceforge.net/
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/intro-and-explanation-about-DataTable-and-DetachableModel-tp16852272p16853277.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]
>
>


-- 
Eyal Golan
[EMAIL PROTECTED]

Visit: http://jvdrums.sourceforge.net/

Reply via email to