- Type Parameters:
T
- Model object.
- All Superinterfaces:
IClusterable
,IDetachable
,Serializable
- All Known Subinterfaces:
IComponentAssignedModel<T>
,IComponentInheritedModel<T>
,IObjectClassAwareModel<T>
,IPropertyReflectionAwareModel<T>
,IWrapModel<T>
- All Known Implementing Classes:
AbstractCheckBoxModel
,AbstractPropertyModel
,ChainingModel
,CollectionModel
,ComponentDetachableModel
,ComponentModel
,ComponentPropertyModel
,CompoundPropertyModel
,FeedbackMessagesModel
,GenericBaseModel
,GroupsModel
,LambdaModel
,ListItemModel
,ListModel
,LoadableDetachableModel
,MapModel
,Model
,NodeModel
,PropertyModel
,ResourceModel
,SessionIdentifiersModel
,SessionSizeModel
,SetModel
,StringResourceModel
,TimeField.AmPmModel
,TimeField.HoursModel
,TimeField.MinutesModel
,ZonedToLocalDateTimeModel
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
A IModel wraps the actual model Object used by a Component. IModel implementations are used as a
facade for the real model so that users have control over the actual persistence strategy. Note
that objects implementing this interface will be stored in the Session. Hence, you should use
(non-transient) instance variables sparingly.
- Basic Models - To implement a basic (non-detachable) model which holds its entire
state in the Session, you can use the simple model wrapper
Model
. - Detachable Models - IModel inherits a hook,
IDetachable.detach()
, so that interface implementers can detach transient information when a model is no longer being actively used by the framework. This reduces memory use and reduces the expense of replicating the model in a clustered server environment. To implement a detachable model, you should generally extendLoadableDetachableModel
instead of implementing IModel directly. - Property Models - The AbstractPropertyModel class provides default functionality for property models. A property model provides access to a particular property of its wrapped model.
- Compound Property Models - The IModel interface is parameterized by Component,
allowing a model to be shared among several Components. When the
getObject()
method is called, the value returned will depend on the Component which is asking for the value. Likewise, thesetObject(Object)
method sets a different property depending on which Component is doing the setting. For more information on CompoundPropertyModels and model inheritance, seeCompoundPropertyModel
andPage
.
- Author:
- Chris Turner, Eelco Hillenius, Jonathan Locke
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionReturns an IModel, returning the object typed asR
if it is an instance of that type, otherwisenull
.default <R,
U> IModel<R> combineWith
(IModel<U> other, org.danekja.java.util.function.serializable.SerializableBiFunction<? super T, ? super U, R> combiner) Returns aIModel
applying the given combining function to the current model object and to the one from the other model, if they are notnull
.default void
detach()
Detaches model after use.Returns a IModel checking whether the predicate holds for the contained object, if it is notnull
.default <R> IModel<R>
flatMap
(org.danekja.java.util.function.serializable.SerializableFunction<? super T, IModel<R>> mapper) Returns a IModel applying the given IModel-bearing mapper to the contained object, if it is notnull
.Gets the model object.Returns a IModel, returning whether the contained object is non-null.default <R> IModel<R>
Returns a IModel applying the given mapper to the contained object, if it is notnull
.static <T> IModel<T>
Suppresses generics warning when casting model types.Returns a IModel, returning either the contained object or the given default value, depending on thenull
ness of the contained object.Returns a IModel, returning either the contained object or invoking the given supplier to get a default value.default void
Sets the model object.
-
Method Details
-
getObject
Gets the model object.- Returns:
- The model object
-
setObject
Sets the model object.- Parameters:
object
- The model object- Throws:
UnsupportedOperationException
- unless overridden
-
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 interfaceIDetachable
-
filter
default IModel<T> filter(org.danekja.java.util.function.serializable.SerializablePredicate<? super T> predicate) Returns a IModel checking whether the predicate holds for the contained object, if it is notnull
. If the predicate doesn't evaluate totrue
, the contained object will benull
.- Parameters:
predicate
- a predicate to be used for testing the contained object- Returns:
- a new IModel
-
map
default <R> IModel<R> map(org.danekja.java.util.function.serializable.SerializableFunction<? super T, R> mapper) Returns a IModel applying the given mapper to the contained object, if it is notnull
.- Type Parameters:
R
- the new type of the contained object- Parameters:
mapper
- a mapper, to be applied to the contained object- Returns:
- a new IModel
-
combineWith
default <R,U> IModel<R> combineWith(IModel<U> other, org.danekja.java.util.function.serializable.SerializableBiFunction<? super T, ? super U, R> combiner) Returns aIModel
applying the given combining function to the current model object and to the one from the other model, if they are notnull
.- Type Parameters:
R
- the resulting typeU
- the other models type- Parameters:
other
- another model to be combined with this onecombiner
- a function combining this and the others object to a result.- Returns:
- a new IModel
-
flatMap
default <R> IModel<R> flatMap(org.danekja.java.util.function.serializable.SerializableFunction<? super T, IModel<R>> mapper) Returns a IModel applying the given IModel-bearing mapper to the contained object, if it is notnull
.- Type Parameters:
R
- the new type of the contained object- Parameters:
mapper
- a mapper, to be applied to the contained object- Returns:
- a new IModel
- See Also:
-
orElse
Returns a IModel, returning either the contained object or the given default value, depending on thenull
ness of the contained object.Possible usages:
myComponent = new AnyComponent("someId", someModel.orElse(defaultValue));
- This way Wicket will make use of the default value if the model object of someModel isnull
.- in the middle of the application logic:
... = someModel.orElse(default).getModelObject();
- Parameters:
other
- a default value- Returns:
- a new IModel
-
orElseGet
default IModel<T> orElseGet(org.danekja.java.util.function.serializable.SerializableSupplier<? extends T> other) Returns a IModel, returning either the contained object or invoking the given supplier to get a default value.- Parameters:
other
- a supplier to be used as a default- Returns:
- a new IModel
-
isPresent
Returns a IModel, returning whether the contained object is non-null.- Returns:
- a new IModel
-
as
Returns an IModel, returning the object typed asR
if it is an instance of that type, otherwisenull
.- Type Parameters:
R
- the type the object should be an instance of- Parameters:
clazz
- theClass
the current model object should be an instance of- Returns:
- a new IModel
-
of
Suppresses generics warning when casting model types.- Type Parameters:
T
-- Parameters:
model
-- Returns:
- cast
model
-