wicket.model
Class AbstractDetachableModel

java.lang.Object
  extended by wicket.model.AbstractDetachableModel
All Implemented Interfaces:
java.io.Serializable, IDetachable, IModel
Direct Known Subclasses:
AbstractPropertyModel, AbstractReadOnlyDetachableModel, FeedbackMessagesModel, ListItemModel

public abstract class AbstractDetachableModel
extends java.lang.Object
implements IModel

This provide a base class to work with detachable IModels. It encapsulates the logic for attaching and detaching models. The onAttach() abstract method will be called at the first access to the model within a request and - if the model was attached earlier, onDetach() will be called at the end of the request. In effect, attachment and detachment is only done when it is actually needed.

Author:
Chris Turner, Eelco Hillenius, Jonathan Locke
See Also:
Serialized Form

Constructor Summary
AbstractDetachableModel()
           
 
Method Summary
 void attach()
          Attaches the model.
 void detach()
          Detaches model after use.
abstract  IModel getNestedModel()
          Gets the nested model.
 java.lang.Object getObject(Component component)
          Gets the model object.
 boolean isAttached()
          Gets whether this model has been attached to the current session.
protected abstract  void onAttach()
          Attaches to the current request.
protected abstract  void onDetach()
          Detaches from the current request.
protected abstract  java.lang.Object onGetObject(Component component)
          Called when getObject is called in order to retrieve the detachable object.
protected abstract  void onSetObject(Component component, java.lang.Object object)
          Called when setObject is called in order to change the detachable object.
 void setObject(Component component, java.lang.Object object)
          Sets the model object.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AbstractDetachableModel

public AbstractDetachableModel()
Method Detail

attach

public final void attach()
Attaches the model.


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
See Also:
IDetachable.detach()

getNestedModel

public abstract IModel getNestedModel()
Description copied from interface: IModel
Gets the nested model.

Specified by:
getNestedModel in interface IModel
Returns:
The nested model object.
See Also:
IModel.getNestedModel()

getObject

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

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

isAttached

public boolean isAttached()
Gets whether this model has been attached to the current session.

Returns:
whether this model has been attached to the current session

setObject

public final void setObject(Component component,
                            java.lang.Object object)
Description copied from interface: IModel
Sets the model object.

Specified by:
setObject in interface IModel
Parameters:
component - The component which wants to set a new model Object
object - The model object
See Also:
IModel.setObject(Component, Object)

toString

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

onAttach

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


onDetach

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


onGetObject

protected abstract java.lang.Object onGetObject(Component component)
Called when getObject is called in order to retrieve the detachable object. Before this method is called, getObject() always calls attach() to ensure that the object is attached.

Parameters:
component - The component asking for the object
Returns:
The object

onSetObject

protected abstract void onSetObject(Component component,
                                    java.lang.Object object)
Called when setObject is called in order to change the detachable object. Before this method is called, setObject() always calls attach() to ensure that the object is attached.

Parameters:
component - The component asking for replacement of the model object
object - The new model object


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