org.apache.wicket.model
Class ComponentDetachableModel<T>

java.lang.Object
  extended by org.apache.wicket.model.ComponentDetachableModel<T>
Type Parameters:
T - The model object type
All Implemented Interfaces:
Serializable, IClusterable, IComponentAssignedModel<T>, IDetachable, IModel<T>

public class ComponentDetachableModel<T>
extends Object
implements IModel<T>, IComponentAssignedModel<T>

Quick detachable model that is implements the IComponentAssignedModel and the IModel interfaces. Its a quick replacement for the current setObject(Component,Object) and getObject(Component) methods when the component is needed in a detachable model.

Author:
jcompagner
See Also:
Serialized Form

Constructor Summary
ComponentDetachableModel()
           
 
Method Summary
protected  void attach()
          Attaches to the current request.
 void detach()
          Detaches from the current request.
 T getObject()
          This getObject throws an exception.
protected  T getObject(Component component)
          Called when getObject is called in order to retrieve the detachable object.
 boolean isAttached()
          Gets whether this model has been attached to the current session.
protected  void setAttached()
          Set this model in an attached state.
protected  void setObject(Component component, T object)
          Called when setObject is called in order to change the detachable object.
 void setObject(T object)
          Sets the model object.
 IWrapModel<T> wrapOnAssignment(Component comp)
          This method is called when the component gets its model assigned.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ComponentDetachableModel

public ComponentDetachableModel()
Method Detail

getObject

public final T getObject()
This getObject throws an exception.

Specified by:
getObject in interface IModel<T>
Returns:
The model object
See Also:
IModel.getObject()

setObject

public final void setObject(T object)
Description copied from interface: IModel
Sets the model object.

Specified by:
setObject in interface IModel<T>
Parameters:
object - The model object
See Also:
IModel.setObject(java.lang.Object)

isAttached

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

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

setAttached

protected final void setAttached()
Set this model in an attached state. Called if the constructor sets the data. (attached)


detach

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

Specified by:
detach in interface IDetachable

attach

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


getObject

protected T getObject(Component component)
Called when getObject is called in order to retrieve the detachable object. Before this method is called, attach() is always called to ensure that the object is attached.

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

setObject

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

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

wrapOnAssignment

public IWrapModel<T> wrapOnAssignment(Component comp)
Description copied from interface: IComponentAssignedModel
This method is called when the component gets its model assigned. WARNING: Because the model can be assigned in the constructor of component this method can also be called with a 'this' of a component that is not fully constructed yet.

Specified by:
wrapOnAssignment in interface IComponentAssignedModel<T>
Returns:
The WrapModel that wraps this model
See Also:
IComponentAssignedModel.wrapOnAssignment(org.apache.wicket.Component)


Copyright © 2004-2011 Apache Software Foundation. All Rights Reserved.