Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Yes, you are right, it is possible to use</p> <pre><code>new CompoundPropertyModel&lt;T&gt;(new LoadableDetachableModel&lt;T&gt; { ... }) </code></pre> <p>or use static creation (it does the same):</p> <pre><code>CompoundPropertyModel.of(new LoadableDetachableModel&lt;T&gt; { ... }) </code></pre> <p>that has both features of compound model and lazy detachable model. Also detaching works correctly, when it CompoudPropertyModel is detached it also proxies detaching to inner model that is used as the model object in this case.</p> <p>I use it in many cases and it works fine.</p> <p><strong>EXPLANATION:</strong> See how looks CompoundPropertyModel class (I'm speaking about Wicket 1.6 right now):</p> <blockquote> <p>public class CompoundPropertyModel&lt;T&gt; extends ChainingModel&lt;T&gt;</p> </blockquote> <p>This mean, CompoundPropertyModel adds the property expression behavior to the ChainingModel.</p> <p>ChainingModel has the following field 'target' and the constructor to set it.</p> <pre><code>private Object target; public ChainingModel(final Object modelObject) { ... target = modelObject; } </code></pre> <p>This take the 'target' reference to tho object or model.</p> <p>When you call getObject() it checks the target and proxies the functionality if the target is a subclass of IModel:</p> <pre><code>public T getObject() { if (target instanceof IModel) { return ((IModel&lt;T&gt;)target).getObject(); } return (T)target; } </code></pre> <p>The similar functionality is implemented for setObject(T), that also sets the target or proxies it if the target is a subclass of IModel</p> <pre><code>public void setObject(T object) { if (target instanceof IModel) { ((IModel&lt;T&gt;)target).setObject(object); } else { target = object; } } </code></pre> <p>The same way is used to detach object, however it check if the target (model object) is detachable, in other words if the target is a subclass if IDetachable, that any of IModel really is.</p> <pre><code>public void detach() { // Detach nested object if it's a detachable if (target instanceof IDetachable) { ((IDetachable)target).detach(); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload