It is meant for general use. I am not entirely happy with the pattern, though I haven't come up with a better one either. You can override it and have quite some options to customize. For example, this is from one of my projects:

public final class ActivityListModel extends AbstractReadOnlyDetachableModel
{
   /** action used by the pageable list (has our order columns). */
private CountAndListAction countAndListAction = new CountAndListAction(); /** the list of matches */
   private transient List list;

   /** number of rows on each page. */
   private final int rowsPerPage;

   /** the venue for this model. */
   private final Venue venue;

   /**
    * Construct.
    * @param venue the venue
    */
   public ActivityListModel(Venue venue)
   {
       this(venue, 14);
   }

   /**
    * Construct.
    * @param venue the venue
    * @param rowsPerPage number of rows on each page
    */
   public ActivityListModel(Venue venue, int rowsPerPage)
   {
       this.venue = venue;
       this.rowsPerPage = rowsPerPage;
   }

   /**
    * Add order-by field to query
    * @param field the field to add
    */
   public final void addOrdering(String field)
   {
       PageableList list = (PageableList)getObject(null);
       if (list != null)
       {
           HibernateCountAndListAction action =
               (HibernateCountAndListAction)list.getCountAndListAction();
           action.addOrdering(field);
           list.clear();
} }

   /**
    * @see wicket.model.IModel#getNestedModel()
    */
   @Override
   public IModel getNestedModel()
   {
       return null;
   }

   /**
    * Gets number of rows on each page.
    * @return number of rows on each page
    */
   public final int getRowsPerPage()
   {
       return rowsPerPage;
   }

   /**
    * Convenience method to figure out if this model has any rows at all.
    * @return whether there are any rows found
    */
   public final boolean hasResults()
   {
       List results = (List)getObject(null);
       return (!results.isEmpty());
   }

   /**
    * @see wicket.model.AbstractDetachableModel#onAttach()
    */
   protected void onAttach()
   {
       if(venue != null)
       {
           list = new PageableList(rowsPerPage, countAndListAction);
       }
       else
       {
           list = Collections.EMPTY_LIST;
       }
   }

   /**
    * @see AbstractDetachableModel#onDetach()
    */
   protected void onDetach()
   {
       list = null;
   }

   /**
    * @see wicket.model.AbstractDetachableModel#onGetObject(Component)
    */
   protected Object onGetObject(final Component component)
   {
       return list;
   }

   /** count and list action that works with this model. */
private final class CountAndListAction extends HibernateCountAndListAction
   {
       /**
        * Construct.
        */
       public CountAndListAction()
       {
           super(new HibernateSessionDelegate());
       }

       @Override
protected void setParameters(Query query, Object queryObject) throws HibernateException
       {
           query.setEntity("venue", venue);
       }

       @Override
       protected Query getQuery(Session session)
       {
           Query query = session.createQuery(
                   "select act from " + Activity.class.getName() +
                   " act.venue = :venue");
           return query;
       }

       @Override
       protected Query getCountQuery(Session session)
       {
           Query query = session.createQuery(
                   "select count(act) from " + Activity.class.getName() +
                   " act.venue = :venue");
           return query;
       }
   }
}

public final class HibernateSessionDelegate implements IHibernateSessionDelegate
{
   /**
* @see wicket.contrib.data.model.hibernate.IHibernateSessionDelegate#getSession()
    */
   public Session getSession()
   {
       return ((BwhRequestCycle)RequestCycle.get()).getHibernateSession();
   }
}


It's a bit verbose, but it works.

Eelco


Phil Kulak wrote:

Hmm... well, in any case, I've been looking at
HibernateCountAndListAction and as of now it's not ready for general
use (it's acutally been hardcoded to the CD demo app). If you look at
getQuery(), it does a lot of string manipulation for setting the ORDER
BY, which could possibly be avoided by using criteria queries. I'm
going to work on a version like that. If it turns into something I'll
post it up.

-Phil

On 6/3/05, Jonathan Carlson <[EMAIL PROTECTED]> wrote:
I don't think the CD app example uses Hibernate to do the paging.  If I
remember right, it reads it all in and does the paging and sorting in
memory.... but I could have missed something.

- Jonathan

[EMAIL PROTECTED] 2005-06-03 11:31:04 AM >>>
I look like I've figured it out anyway, but for future reference,
where is the source for that example? I found the running program. Is
the source only in CVS?

On 6/3/05, Martijn Dashorst <[EMAIL PROTECTED]> wrote:
Phil Kulak wrote:

It looks like you guys have that all figured out in the contrib, but
I
can't seem to figure out how it's supposed to be used from just the
source. Is there an example anywhere I could look at?


You could take a look at the CD-App example. This one is rather
feature
complete. It is member of the wicket-stuff project under the
wicket-contrib-examples.

Martijn


-------------------------------------------------------
This SF.Net email is sponsored by Yahoo.
Introducing Yahoo! Search Developer Network - Create apps using
Yahoo!
Search APIs Find out how you can build Yahoo! directly into your own
Applications - visit
http://developer.yahoo.net/?fr=offad-ysdn-ostg-q22005
_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user

-------------------------------------------------------
This SF.Net email is sponsored by Yahoo.
Introducing Yahoo! Search Developer Network - Create apps using Yahoo!
Search APIs Find out how you can build Yahoo! directly into your own
Applications - visit
http://developer.yahoo.net/?fr=offad-ysdn-ostg-q22005
_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user

______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email
______________________________________________________________________

______________________________________________________________________
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

Katun Corporation -- www.katun.com
_____________________________________________________________________


-------------------------------------------------------
This SF.Net email is sponsored by: NEC IT Guy Games.  How far can you shotput
a projector? How fast can you ride your desk chair down the office luge track?
If you want to score the big prize, get to know the little guy.
Play to win an NEC 61" plasma display: http://www.necitguy.com/?r=20
_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user



-------------------------------------------------------
This SF.Net email is sponsored by: NEC IT Guy Games.  How far can you shotput
a projector? How fast can you ride your desk chair down the office luge track?
If you want to score the big prize, get to know the little guy. Play to win an NEC 61" plasma display: http://www.necitguy.com/?r _______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user



-------------------------------------------------------
This SF.Net email is sponsored by: NEC IT Guy Games.  How far can you shotput
a projector? How fast can you ride your desk chair down the office luge track?
If you want to score the big prize, get to know the little guy. Play to win an NEC 61" plasma display: http://www.necitguy.com/?r=20
_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user

Reply via email to