You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by pa...@apache.org on 2020/01/08 10:22:13 UTC

[wicket] branch master updated: Re-introduce ChainingModel.getChainedModel and update docs

This is an automated email from the ASF dual-hosted git repository.

papegaaij pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/wicket.git


The following commit(s) were added to refs/heads/master by this push:
     new b4716f8  Re-introduce ChainingModel.getChainedModel and update docs
b4716f8 is described below

commit b4716f8bd3434ad2332fe0b156ffe296e3c750d0
Author: Emond Papegaaij <em...@topicus.nl>
AuthorDate: Wed Jan 8 11:21:54 2020 +0100

    Re-introduce ChainingModel.getChainedModel and update docs
---
 .../org/apache/wicket/model/ChainingModel.java     | 31 ++++++++++++++++++----
 .../apache/wicket/model/CompoundPropertyModel.java |  2 +-
 .../main/asciidoc/modelsforms/modelsforms_6.adoc   |  2 +-
 3 files changed, 28 insertions(+), 7 deletions(-)

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 8042869..2889878 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
@@ -22,15 +22,24 @@ import org.apache.wicket.Session;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+
 /**
- * Default implementation of IChainingModel
- *
+ * This model and its subclasses support chaining of IModels. {@code getObject()} of 
+ * {@code ChainingModel} returns its object like this:
+ * 
+ * <pre>
+ * if ( object instanceof IModel) { return ((IModel)object).getObject()}
+ * else return object;
+ * </pre>
+ * 
+ * ChainingModel also detaches the inner model on detach.
+ * 
  * @param <T>
  *            The Model object type
- *
+ * 
  * @see CompoundPropertyModel
  * @see AbstractPropertyModel
- *
+ * 
  * @since 6.0.0
  */
 public class ChainingModel<T> implements IModel<T>
@@ -100,7 +109,7 @@ public class ChainingModel<T> implements IModel<T>
 	/**
 	 * @return The target - object or model
 	 */
-	protected final Object getTarget()
+	public final Object getTarget()
 	{
 		return target;
 	}
@@ -114,6 +123,18 @@ public class ChainingModel<T> implements IModel<T>
 		this.target = modelObject;
 		return this;
 	}
+	
+	/**
+	 * @return The target - if it is a model, null otherwise
+	 */
+	public IModel<?> getChainedModel()
+	{
+		if (target instanceof IModel)
+		{
+			return (IModel<?>)target;
+		}
+		return null;
+	}
 
 	@Override
 	public String toString()
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 6f821d8..3951355 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
@@ -30,7 +30,7 @@ import org.apache.wicket.Component;
  * @see org.apache.wicket.model.IModel
  * @see org.apache.wicket.model.Model
  * @see org.apache.wicket.model.LoadableDetachableModel
- * @see IChainingModel
+ * @see ChainingModel
  * 
  * @author Jonathan Locke
  * 
diff --git a/wicket-user-guide/src/main/asciidoc/modelsforms/modelsforms_6.adoc b/wicket-user-guide/src/main/asciidoc/modelsforms/modelsforms_6.adoc
index 92985a3..5b68d4b 100644
--- a/wicket-user-guide/src/main/asciidoc/modelsforms/modelsforms_6.adoc
+++ b/wicket-user-guide/src/main/asciidoc/modelsforms/modelsforms_6.adoc
@@ -1,7 +1,7 @@
 
 
 
-Models that implement the interface _org.apache.wicket.model.IChainingModel_ can be used to build a chain of models. These kinds of models are able to recognize whether their model object is itself an implementation of IModel and if so, they will call getObject on the wrapped model and the returned value will be the actual model object. In this way we can combine the action of an arbitrary number of models, making exactly a chain of models. Chaining models allows to combine different dat [...]
+Models that extend _org.apache.wicket.model.ChainingModel_ can be used to build a chain of models. These models are able to recognize whether their model object is itself an implementation of IModel and if so, they will call getObject on the wrapped model and the returned value will be the actual model object. In this way we can combine the action of an arbitrary number of models, making exactly a chain of models. Chaining models allows to combine different data persistence strategies, s [...]
 
 The example page will look like this: