Class LambdaModel<T>

java.lang.Object
org.apache.wicket.model.LambdaModel<T>
Type Parameters:
T - The type of the Model Object
All Implemented Interfaces:
Serializable, IDetachable, IModel<T>, IClusterable

public abstract class LambdaModel<T> extends Object implements IModel<T>
LambdaModel is a basic implementation of an IModel that uses a serializable Supplier to get the object and Consumer to set it.
See Also:
  • Method Details

    • setObject

      public void setObject(T t)
      Description copied from interface: IModel
      Sets the model object.
      Specified by:
      setObject in interface IModel<T>
      Parameters:
      t - The model object
    • of

      public static <R> IModel<R> of(org.danekja.java.util.function.serializable.SerializableSupplier<R> getter)
      Create a read-only IModel. Usage:
       
           LambdaModel.of(person::getName)
       
       
      Note that IModel is a FunctionalInterface and you can also use a lambda directly as a model.
      Type Parameters:
      R - model object type
      Parameters:
      getter - used to get value
      Returns:
      model
    • of

      public static <R> IModel<R> of(org.danekja.java.util.function.serializable.SerializableSupplier<R> getter, org.danekja.java.util.function.serializable.SerializableConsumer<R> setter)
      Create a LambdaModel. Usage:
       
       	LambdaModel.of(person::getName, person::setName)
       
       
      Type Parameters:
      R - model object type
      Parameters:
      getter - used to get value
      setter - used to set value
      Returns:
      model
    • of

      public static <X, R> IModel<R> of(IModel<X> target, org.danekja.java.util.function.serializable.SerializableFunction<X,R> getter, org.danekja.java.util.function.serializable.SerializableBiConsumer<X,R> setter)
      Create a LambdaModel for a given target. Usage:
       
       	LambdaModel.of(personModel, Person::getName, Person::setName)
       
       
      The target model will be detached automatically.
      Type Parameters:
      X - target model object type
      R - model object type
      Parameters:
      target - target for getter and setter
      getter - used to get a value
      setter - used to set a value
      Returns:
      model
      See Also: