Interface IModel<T>

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.

@FunctionalInterface public interface IModel<T> extends IDetachable
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 extend LoadableDetachableModel 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, the setObject(Object)method sets a different property depending on which Component is doing the setting. For more information on CompoundPropertyModels and model inheritance, see CompoundPropertyModeland Page.
Author:
Chris Turner, Eelco Hillenius, Jonathan Locke
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    default <R extends T>
    IModel<R>
    as(Class<R> clazz)
    Returns an IModel, returning the object typed as R if it is an instance of that type, otherwise null.
    default <R, U> IModel<R>
    combineWith(IModel<U> other, org.danekja.java.util.function.serializable.SerializableBiFunction<? super T,? super U,R> combiner)
    Returns a IModel applying the given combining function to the current model object and to the one from the other model, if they are not null.
    default void
    Detaches model after use.
    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 not null.
    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 not null.
    Gets the model object.
    default IModel<Boolean>
    Returns a IModel, returning whether the contained object is non-null.
    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 not null.
    static <T> IModel<T>
    of(IModel<?> model)
    Suppresses generics warning when casting model types.
    default IModel<T>
    orElse(T other)
    Returns a IModel, returning either the contained object or the given default value, depending on the nullness of the contained object.
    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.
    default void
    setObject(T object)
    Sets the model object.
  • Method Details

    • getObject

      Gets the model object.
      Returns:
      The model object
    • setObject

      default void setObject(T object)
      Sets the model object.
      Parameters:
      object - The model object
      Throws:
      UnsupportedOperationException - unless overridden
    • detach

      default 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
    • 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 not null. If the predicate doesn't evaluate to true, the contained object will be null.
      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 not null.
      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 a IModel applying the given combining function to the current model object and to the one from the other model, if they are not null.
      Type Parameters:
      R - the resulting type
      U - the other models type
      Parameters:
      other - another model to be combined with this one
      combiner - 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 not null.
      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

      default IModel<T> orElse(T other)
      Returns a IModel, returning either the contained object or the given default value, depending on the nullness of the contained object.

      Possible usages:

      • myComponent = new AnyComponent(&quot;someId&quot;, someModel.orElse(defaultValue)); - This way Wicket will make use of the default value if the model object of someModel is null.
      • 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

      default IModel<Boolean> isPresent()
      Returns a IModel, returning whether the contained object is non-null.
      Returns:
      a new IModel
    • as

      default <R extends T> IModel<R> as(Class<R> clazz)
      Returns an IModel, returning the object typed as R if it is an instance of that type, otherwise null.
      Type Parameters:
      R - the type the object should be an instance of
      Parameters:
      clazz - the Class the current model object should be an instance of
      Returns:
      a new IModel
    • of

      static <T> IModel<T> of(IModel<?> model)
      Suppresses generics warning when casting model types.
      Type Parameters:
      T -
      Parameters:
      model -
      Returns:
      cast model