wicket.model
Class LoadableDetachableModel

java.lang.Object
  extended by wicket.model.AbstractModel
      extended by wicket.model.AbstractReadOnlyModel
          extended by wicket.model.LoadableDetachableModel
All Implemented Interfaces:
java.io.Serializable, IDetachable, IModel

public abstract class LoadableDetachableModel
extends AbstractReadOnlyModel

Model that makes working with detachable models a breeze. LoadableDetachableModel holds a temporary, transient model object, that is set when getObject(Component) is called by calling abstract method 'load', and that will be reset/ set to null on detach(). A usage example:

 LoadableDetachableModel venueListModel = new LoadableDetachableModel()
 {
        protected Object load()
        {
                return getVenueDao().findVenues();
        }
 };
 

Though you can override methods onAttach() and onDetach() for additional attach/ detach behavior, the point of this class is to hide as much of the attaching/ detaching as possible. So you should rarely need to override those methods, if ever.

Author:
Eelco Hillenius, Igor Vaynberg
See Also:
Serialized Form

Constructor Summary
LoadableDetachableModel()
          Construct.
LoadableDetachableModel(java.lang.Object object)
          This constructor is used if you already have the object retrieved and want to wrap it with a detachable model.
 
Method Summary
 void detach()
          Detaches model after use.
 java.lang.Object getObject(Component component)
          Gets the model object.
 boolean isAttached()
          Gets the attached status of this model instance
protected abstract  java.lang.Object load()
          Loads and returns the (temporary) model object.
protected  void onAttach()
          Attaches to the current request.
protected  void onDetach()
          Detaches from the current request.
 java.lang.String toString()
           
 
Methods inherited from class wicket.model.AbstractReadOnlyModel
setObject
 
Methods inherited from class wicket.model.AbstractModel
getNestedModel
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

LoadableDetachableModel

public LoadableDetachableModel()
Construct.


LoadableDetachableModel

public LoadableDetachableModel(java.lang.Object object)
This constructor is used if you already have the object retrieved and want to wrap it with a detachable model.

Parameters:
object - retrieved instance of the detachable object
Method Detail

detach

public final void detach()
Description copied from interface: IDetachable
Detaches model after use. This is generally used to null out transient references that can be re-attached later.

Specified by:
detach in interface IDetachable
Overrides:
detach in class AbstractModel
See Also:
IDetachable.detach()

getObject

public java.lang.Object getObject(Component component)
Description copied from interface: IModel
Gets the model object.

Specified by:
getObject in interface IModel
Specified by:
getObject in class AbstractReadOnlyModel
Parameters:
component - The component which wants to get a model Object
Returns:
The model object
See Also:
IModel.getObject(wicket.Component)

isAttached

public final boolean isAttached()
Gets the attached status of this model instance

Returns:
true if the model is attached, false otherwise

toString

public java.lang.String toString()
Overrides:
toString in class AbstractReadOnlyModel
See Also:
Object.toString()

load

protected abstract java.lang.Object load()
Loads and returns the (temporary) model object.

Returns:
the (temporary) model object

onAttach

protected void onAttach()
Attaches to the current request. Implement this method with custom behavior, such as loading the model object.


onDetach

protected void onDetach()
Detaches from the current request. Implement this method with custom behavior, such as setting the model object to null.



Copyright © 2004-2007 Wicket developers. All Rights Reserved.