T - The Model Object typepublic abstract class LoadableDetachableModel<T> extends Object implements IModel<T>
getObject() 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.
| Constructor and Description |
|---|
LoadableDetachableModel()
Default constructor, constructs the model in detached state with no data associated with the
model.
|
LoadableDetachableModel(T object)
This constructor is used if you already have the object retrieved and want to wrap it with a
detachable model.
|
| Modifier and Type | Method and Description |
|---|---|
void |
detach()
Detaches model after use.
|
T |
getObject()
Gets the model object.
|
boolean |
isAttached()
Gets the attached status of this model instance
|
protected abstract T |
load()
Loads and returns the (temporary) model object.
|
protected void |
onAttach()
Attaches to the current request.
|
protected void |
onDetach()
Detaches from the current request.
|
void |
setObject(T object)
Manually loads the model with the specified object.
|
String |
toString() |
public LoadableDetachableModel()
public LoadableDetachableModel(T object)
getObject() will
return object until detach() is called.object - retrieved instance of the detachable objectpublic void detach()
IDetachabledetach in interface IDetachableIDetachable.detach()public final T getObject()
IModelgetObject in interface IModel<T>IModel.getObject()public final boolean isAttached()
public String toString()
toString in class ObjectObject.toString()protected abstract T load()
protected void onAttach()
protected void onDetach()
Copyright © 2006–2021 Apache Software Foundation. All rights reserved.