You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by mg...@apache.org on 2017/08/06 11:58:48 UTC
[3/7] wicket git commit: WICKET-6432 added factory method for
non-model targetChainingModel logs warning now if target is not serializable
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/2472fa08
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/2472fa08
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/2472fa08
Branch: refs/heads/master
Commit: 2472fa08f39ec4607e6d69ca3677a3dded368e12
Parents: 1f7b447
Author: Sven Meier <sv...@apache.org>
Authored: Sun Aug 6 09:24:04 2017 +0200
Committer: Martin Tzvetanov Grigorov <mg...@apache.org>
Committed: Sun Aug 6 14:53:00 2017 +0300
----------------------------------------------------------------------
.../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/2472fa08/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/2472fa08/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..6146529 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);
+ }
}