You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Alexander Morozov <al...@gmail.com> on 2011/02/01 17:16:00 UTC

[1.4.15] FLAG_INHERITABLE_MODEL and default model change

Hi,

I have the question about correctness of Component#setDefaultModel
(Component#setModelImpl) method behavior. I expect that the flag
FLAG_INHERITABLE_MODEL should be checked there and turned off if the
provided model is not a IComponentInheritedModel.

Let check the next code:


public MyPanel(String id) {
 super(id);
  ...
  form.setModel(new CompoundPropertyModel(this));
  DropDownChoice ddc = new DropDownChoice("variant", Arrays.ofList(...)) {   
// p1
    @Override
    protected void onInitialize() {
       super.onInitialize();
       setModel(new DefaultingWrapModel(getModel(), Model.of("default
value"));            // p2
    }
  };
  ddc.setNullValid(false);
  ddc.setRequired(true);
  form.add(ddc);
  ...
}


In the (p1) the DDC will initialize with CompoundPropertyModel and the
FLAG_INHERITABLE_MODEL will be turned on soon by the first invocation of
FormComponent#getModel().

In the (p2) we wrap the DDC model with the model which provide the default
value (DefaultingWrapModel implements IWrapModel). So we change the model,
but the FLAG_INHERITABLE_MODEL is still turned on.

On the Component#detach() event, the method Component#setModelImpl(null)
will be invoked for the ddc and the DefaultingWrapModel instance will be
lost

		// reset the model to null when the current model is a IWrapModel and
		// the model that created it/wrapped in it is a IComponentInheritedModel
		// The model will be created next time.
		if (getFlag(FLAG_INHERITABLE_MODEL))
		{
			setModelImpl(null);
			setFlag(FLAG_INHERITABLE_MODEL, false);
		}


I think that such behavior is unexpected. Am I right :) ?

Thanks

-- 
View this message in context: http://apache-wicket.1842946.n4.nabble.com/1-4-15-FLAG-INHERITABLE-MODEL-and-default-model-change-tp3252093p3252093.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: [1.4.15] FLAG_INHERITABLE_MODEL and default model change

Posted by Alexander Morozov <al...@gmail.com>.
Igor, I have one more question about IWrapModel :

why the Component#defaultModelComparator doesn't check and unwrap IWrapModel
before calling the IModel#getObject() ?


	private static final IModelComparator defaultModelComparator = new
IModelComparator()
	{
		private static final long serialVersionUID = 1L;

		public boolean compare(Component component, Object b)
		{
                        //final Object a =
component.getDefaultModelObject();
                        // the default model can act as IWrapModel
			final Object a = component.getInnermostModel().getObject();
			if (a == null && b == null)
			{
				return true;
			}
			if (a == null || b == null)
			{
				return false;
			}
			return a.equals(b);
		}
	};


In the sample above  with DDC, if we use the DefaultingWrapModel,
defaultModelComparator will always return true (in case of default value
selection) and the default model object will never updated because of :
Component#setDefaultModelObject(final Object object)

		// Check whether this will result in an actual change
		if (!getModelComparator().compare(this, object))
		{
			modelChanging();
			model.setObject(object);
			modelChanged();
		}

-- 
View this message in context: http://apache-wicket.1842946.n4.nabble.com/1-4-15-FLAG-INHERITABLE-MODEL-and-default-model-change-tp3252093p3254620.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: [1.4.15] FLAG_INHERITABLE_MODEL and default model change

Posted by Alexander Morozov <al...@gmail.com>.
Done

https://issues.apache.org/jira/browse/WICKET-3413
-- 
View this message in context: http://apache-wicket.1842946.n4.nabble.com/1-4-15-FLAG-INHERITABLE-MODEL-and-default-model-change-tp3252093p3254349.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: [1.4.15] FLAG_INHERITABLE_MODEL and default model change

Posted by Igor Vaynberg <ig...@gmail.com>.
please file a jira

-igor


On Tue, Feb 1, 2011 at 8:16 AM, Alexander Morozov
<al...@gmail.com> wrote:
>
> Hi,
>
> I have the question about correctness of Component#setDefaultModel
> (Component#setModelImpl) method behavior. I expect that the flag
> FLAG_INHERITABLE_MODEL should be checked there and turned off if the
> provided model is not a IComponentInheritedModel.
>
> Let check the next code:
>
>
> public MyPanel(String id) {
>  super(id);
>  ...
>  form.setModel(new CompoundPropertyModel(this));
>  DropDownChoice ddc = new DropDownChoice("variant", Arrays.ofList(...)) {
> // p1
>    @Override
>    protected void onInitialize() {
>       super.onInitialize();
>       setModel(new DefaultingWrapModel(getModel(), Model.of("default
> value"));            // p2
>    }
>  };
>  ddc.setNullValid(false);
>  ddc.setRequired(true);
>  form.add(ddc);
>  ...
> }
>
>
> In the (p1) the DDC will initialize with CompoundPropertyModel and the
> FLAG_INHERITABLE_MODEL will be turned on soon by the first invocation of
> FormComponent#getModel().
>
> In the (p2) we wrap the DDC model with the model which provide the default
> value (DefaultingWrapModel implements IWrapModel). So we change the model,
> but the FLAG_INHERITABLE_MODEL is still turned on.
>
> On the Component#detach() event, the method Component#setModelImpl(null)
> will be invoked for the ddc and the DefaultingWrapModel instance will be
> lost
>
>                // reset the model to null when the current model is a IWrapModel and
>                // the model that created it/wrapped in it is a IComponentInheritedModel
>                // The model will be created next time.
>                if (getFlag(FLAG_INHERITABLE_MODEL))
>                {
>                        setModelImpl(null);
>                        setFlag(FLAG_INHERITABLE_MODEL, false);
>                }
>
>
> I think that such behavior is unexpected. Am I right :) ?
>
> Thanks
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/1-4-15-FLAG-INHERITABLE-MODEL-and-default-model-change-tp3252093p3252093.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org