Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Provide serializable versions of java.util.function.(Supplier|Consumer|Function) 
Jira
serverASF JIRA
serverId5aa69414-a9e9-3523-82ec-879b028fb15b
keyWICKET-5991

java.util.function.Consumer and other classes are not serializable and this makes them unusable in stateful Wicket pages. For this reason Wicket provides org.apache.wicket.model.lambda.WicketSupplier, org.apache.wicket.model.lambda.WicketConsumer and org.apache.wicket.model.lambda.WicketFunction. Those interfaces should be used in method signatures where Java 8 lambdas or method references could be used. At the call site there is nothing specific to be done, i.e. just use lambdas and method references without any casting.

 

Provide IModel implementations which make use of Java 8 lambdas and method references 
Jira
serverASF JIRA
serverId5aa69414-a9e9-3523-82ec-879b028fb15b
keyWICKET-5991

Wicket provides three new implementations of IModel which use Java 8 consumers and suppliers, i.e. may be used with lambda or method references.

  • org.apache.wicket.model.lambda.LambdaModel.

    Code Block
    languagejava
    titleLambdaModel
    collapsetrue
    Person person = ...;
    IModel<String> personNameModel = new LambdaModel<>(
          () -> person.getName(),
          (name) -> person.setName(name));

    org.apache.wicket.model.lambda.SupplierModel. It is similar to org.apache.wicket.model.AbstractReadOnlyModel.

    Code Block
    languagejava
    titleSupplierModel
    collapsetrue
    Person person = ...;
    IModel<String> personNameModel = new SupplierModel<>(person::getName);
  • org.apache.wicket.model.lambda.SupplierCachingModel. It is similar to org.apache.wicket.model.LoadableDetachableModel 

    Code Block
    languagejava
    titleSupplierCachingModel
    collapsetrue
    Person person = ...;
    IModel<String> personNameModel = new SupplierCachingModel<>(person::getName);

IGenericComponent is a mixin/trait interface 
Jira
serverASF JIRA
serverId5aa69414-a9e9-3523-82ec-879b028fb15b
keyWICKET-6117

IGenericComponent uses Java 8 default methods to implement #setModel(IModel<T>), #getModel(), #setModelObject(T) and #getModelObject() by delegating to the respective get/setDefaultModel[Object] methods.

This way it could be easily used by any Component by just implementing it.

IModel is a @FunctionalInterface now

IModel provides default implementations of #detach() (do nothing) and #setObject(T) (throws UnsupportedOperationException), so it is possible to use it as a functional interface.

Code Block
languagejava
titleIModel as functional interface
collapsetrue
new Link<String>("", () -> "abc") {
   @Override
   public void onClick()
   {
     // ...
   }
};
 
Label label = new Label("id", person::getName); // the method reference is actually IModel<String>

 

Dependency updates

All libraries on which Wicket modules depend are updated to their latest stable versions.
The most notable ones are:

...