Repository: wicket Updated Branches: refs/heads/master c5f758e4a -> f9a9bf9c3
WICKET-6432 added factory method for non-model targetChainingModel logs warning now if target is not serializable Project: http://git-wip-us.apache.org/repos/asf/wicket/repo Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/f9a9bf9c Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/f9a9bf9c Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/f9a9bf9c Branch: refs/heads/master Commit: f9a9bf9c3fb0b1390b6600d027bb64ae7e4f3c03 Parents: c5f758e Author: Sven Meier <svenme...@apache.org> Authored: Sun Aug 6 09:24:04 2017 +0200 Committer: Sven Meier <svenme...@apache.org> Committed: Sun Aug 6 09:24:39 2017 +0200 ---------------------------------------------------------------------- .../java/org/apache/wicket/model/ChainingModel.java | 6 ++++++ .../apache/wicket/model/CompoundPropertyModel.java | 16 ++++++++++++++++ 2 files changed, 22 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/wicket/blob/f9a9bf9c/wicket-core/src/main/java/org/apache/wicket/model/ChainingModel.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/main/java/org/apache/wicket/model/ChainingModel.java b/wicket-core/src/main/java/org/apache/wicket/model/ChainingModel.java index 8d8df3f..fa0ca7a 100644 --- a/wicket-core/src/main/java/org/apache/wicket/model/ChainingModel.java +++ b/wicket-core/src/main/java/org/apache/wicket/model/ChainingModel.java @@ -16,6 +16,8 @@ */ package org.apache.wicket.model; +import java.io.Serializable; + import org.apache.wicket.Session; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -46,6 +48,10 @@ public class ChainingModel<T> implements IChainingModel<T> + "in models directly as it may lead to serialization problems. " + "If you need to access a property of the session via the model use the " + "page instance as the model object and 'session.attribute' as the path."); + } else if (modelObject instanceof Serializable == false) + { + LOG.warn("It is not a good idea to reference a non-serializable instance " + + "in models directly as it may lead to serialization problems."); } target = modelObject; http://git-wip-us.apache.org/repos/asf/wicket/blob/f9a9bf9c/wicket-core/src/main/java/org/apache/wicket/model/CompoundPropertyModel.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/main/java/org/apache/wicket/model/CompoundPropertyModel.java b/wicket-core/src/main/java/org/apache/wicket/model/CompoundPropertyModel.java index 50bd4a0..74bf429 100644 --- a/wicket-core/src/main/java/org/apache/wicket/model/CompoundPropertyModel.java +++ b/wicket-core/src/main/java/org/apache/wicket/model/CompoundPropertyModel.java @@ -16,6 +16,8 @@ */ package org.apache.wicket.model; +import java.io.Serializable; + import org.apache.wicket.Component; /** @@ -155,4 +157,18 @@ public class CompoundPropertyModel<T> extends ChainingModel<T> implements ICompo { return new CompoundPropertyModel<>(model); } + + /** + * Type-infering factory method + * + * @param <Z> + * the type of the model's object + * @param object + * model object + * @return {@link CompoundPropertyModel} instance + */ + public static <Z extends Serializable> CompoundPropertyModel<Z> of(Z object) + { + return new CompoundPropertyModel<>(object); + } }