Repository: wicket Updated Branches: refs/heads/master 2b8ba3a6e -> 061c0e903
Added some documentation for IModel lambda support Project: http://git-wip-us.apache.org/repos/asf/wicket/repo Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/061c0e90 Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/061c0e90 Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/061c0e90 Branch: refs/heads/master Commit: 061c0e9038c8f72d19b89efbb9188912f0289e6c Parents: 2b8ba3a Author: Andrea Del Bene <[email protected]> Authored: Thu Aug 11 14:55:44 2016 +0200 Committer: Andrea Del Bene <[email protected]> Committed: Thu Aug 11 14:56:38 2016 +0200 ---------------------------------------------------------------------- .../java/org/apache/wicket/model/IModel.java | 6 ++-- .../docs/guide/modelsforms/modelsforms_2.gdoc | 30 +++++++++++++++++--- 2 files changed, 29 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/wicket/blob/061c0e90/wicket-core/src/main/java/org/apache/wicket/model/IModel.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/main/java/org/apache/wicket/model/IModel.java b/wicket-core/src/main/java/org/apache/wicket/model/IModel.java index d6c64bb..cfb6bfe 100644 --- a/wicket-core/src/main/java/org/apache/wicket/model/IModel.java +++ b/wicket-core/src/main/java/org/apache/wicket/model/IModel.java @@ -138,8 +138,8 @@ public interface IModel<T> extends IDetachable } /** - * Returns a IModel applying the given combining function to the contained object of this and - * the given other model, if they are not null. + * 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. * * @param <R> * the resulting type @@ -171,7 +171,7 @@ public interface IModel<T> extends IDetachable } /** - * Returns a IModel applying the given mapper to the contained object, if it is not NULL. + * Returns a IModel applying the given IModel-bearing mapper to the contained object, if it is not NULL. * * @param <R> * the new type of the contained object http://git-wip-us.apache.org/repos/asf/wicket/blob/061c0e90/wicket-user-guide/src/docs/guide/modelsforms/modelsforms_2.gdoc ---------------------------------------------------------------------- diff --git a/wicket-user-guide/src/docs/guide/modelsforms/modelsforms_2.gdoc b/wicket-user-guide/src/docs/guide/modelsforms/modelsforms_2.gdoc index 4fd15ce..faa79c9 100644 --- a/wicket-user-guide/src/docs/guide/modelsforms/modelsforms_2.gdoc +++ b/wicket-user-guide/src/docs/guide/modelsforms/modelsforms_2.gdoc @@ -29,15 +29,37 @@ Most of the default methods we find in @IModel@ are meant to leverage Lambda exp //the filtered model will have a null model object if person's name //is not "Jane" IModel<Person> janeModel = Model.of(person) - .filter((p) -> p.getName().equals("Jane")); + .filter((p) -> p.getName().equals("Jane")); {code} {divcontainer} * *map(mapperFunction)*: Returns a @IModel@ applying the given mapper to the contained object, if it is not null. Example: {divcontainer:li-nested-content} {code:java} - //the new model will contain the person's first name - IModel<String> personNameModel = Model.of(person).map(Person::getName); + //the new read-only model will contain the person's first name + IModel<String> personNameModel = Model.of(person).map(Person::getName); {code} {divcontainer} - +* *flatMap(mapperFunction)*: Returns a @IModel@ applying the given @IModel@-bearing mapper to the contained object, if it is not null. Example: + {divcontainer:li-nested-content} + {code:java} + //returns a read/write model for person's first name + //NOTE: LambdaModel will be discussed later. + IModel<String> personNameModel = Model.of(person).flatMap(targetPerson -> + LambdaModel.of( + () -> targetPerson::getName, targetPerson::setName + )); + {code} + {divcontainer} + * *flatMap(otherModel, 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. Example: + {divcontainer:li-nested-content} + {code:java} + Model<String> hello = Model.of("hello"); + Model<String> world = Model.of("world"); + IModel<String> combinedModel = hello.combineWith( + world, (thisObj, otherObj) -> thisObj + " " + otherObj); + + assertEquals("hello world", combinedModel.getObject()); + {code} + {divcontainer} + TODO:add other methods
