Package org.apache.wicket.model
Class Model<T extends java.io.Serializable>
- java.lang.Object
-
- org.apache.wicket.model.Model<T>
-
- Type Parameters:
T- The type of the Model Object
- All Implemented Interfaces:
java.io.Serializable,IDetachable,IModel<T>,IObjectClassAwareModel<T>,org.apache.wicket.util.io.IClusterable
public class Model<T extends java.io.Serializable> extends java.lang.Object implements IObjectClassAwareModel<T>
Modelis the basic implementation of anIModel. It just wraps a simple model object. The model object must be serializable, as it is stored in the session. If you have large objects to store, consider usingLoadableDetachableModelinstead of this class.- Author:
- Chris Turner, Eelco Hillenius
- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddetach()Detaches model after use.booleanequals(java.lang.Object obj)TgetObject()Gets the model object.java.lang.Class<T>getObjectClass()Returns the class of model objectinthashCode()static <T extends java.io.Serializable>
Model<T>of()Factory methods for Model which uses type inference to make code shorter.static <C> IModel<java.util.Collection<C>>of(java.util.Collection<C> collection)Factory method for models that contain collections.static <T extends java.io.Serializable>
Model<T>of(T object)Factory methods for Model which uses type inference to make code shorter.static <C> IModel<java.util.List<C>>ofList(java.util.List<C> list)Factory method for models that contain lists.static <K,V>
IModel<java.util.Map<K,V>>ofMap(java.util.Map<K,V> map)Factory method for models that contain maps.static <C> IModel<java.util.Set<C>>ofSet(java.util.Set<C> set)Factory method for models that contain sets.voidsetObject(T object)Set the model object; calls setObject(java.io.Serializable).java.lang.StringtoString()
-
-
-
Constructor Detail
-
Model
public Model()
Construct the model without providing an object.
-
Model
public Model(T object)
Construct the model, setting the given object as the wrapped object.- Parameters:
object- The model object proper
-
-
Method Detail
-
ofList
public static <C> IModel<java.util.List<C>> ofList(java.util.List<C> list)
Factory method for models that contain lists. This factory method will automatically rebuild a non-serializablelistinto a serializable one.- Type Parameters:
C- model type- Parameters:
list- The List, which may or may not be Serializable- Returns:
- A Model object wrapping the List
-
ofMap
public static <K,V> IModel<java.util.Map<K,V>> ofMap(java.util.Map<K,V> map)
Factory method for models that contain maps. This factory method will automatically rebuild a non-serializablemapinto a serializable one.- Type Parameters:
K- key type in mapV- value type in map- Parameters:
map- The Map, which may or may not be Serializable- Returns:
- A Model object wrapping the Map
-
ofSet
public static <C> IModel<java.util.Set<C>> ofSet(java.util.Set<C> set)
Factory method for models that contain sets. This factory method will automatically rebuild a non-serializablesetinto a serializable one.- Type Parameters:
C- model type- Parameters:
set- The Set, which may or may not be Serializable- Returns:
- A Model object wrapping the Set
-
of
public static <C> IModel<java.util.Collection<C>> of(java.util.Collection<C> collection)
Factory method for models that contain collections. This factory method will automatically rebuild a non-serializablecollectioninto a serializableArrayList.- Type Parameters:
C- model type- Parameters:
collection- The Collection, which may or may not be Serializable- Returns:
- A Model object wrapping the Set
-
of
public static <T extends java.io.Serializable> Model<T> of(T object)
Factory methods for Model which uses type inference to make code shorter. Equivalent tonew Model.(object) - Type Parameters:
T-- Parameters:
object-- Returns:
- Model that contains
object
-
of
public static <T extends java.io.Serializable> Model<T> of()
Factory methods for Model which uses type inference to make code shorter. Equivalent tonew Model.() - Type Parameters:
T-- Returns:
- Model that contains
object
-
setObject
public void setObject(T object)
Set the model object; calls setObject(java.io.Serializable). The model object must be serializable, as it is stored in the session- Specified by:
setObjectin interfaceIModel<T extends java.io.Serializable>- Parameters:
object- the model object- See Also:
IModel.setObject(Object)
-
detach
public void detach()
Description copied from interface:IDetachableDetaches model after use. This is generally used to null out transient references that can be re-attached later.- Specified by:
detachin interfaceIDetachable- Specified by:
detachin interfaceIModel<T extends java.io.Serializable>
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
getObjectClass
public java.lang.Class<T> getObjectClass()
Description copied from interface:IObjectClassAwareModelReturns the class of model object- Specified by:
getObjectClassin interfaceIObjectClassAwareModel<T extends java.io.Serializable>- Returns:
- class of model object or null if the class couldn't be determined
-
-