You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Matthijs Wensveen <m....@func.nl> on 2008/06/10 14:49:18 UTC
ComponentPropertyModel
Hi,
I'm trying to use ComponentPropertyModel as a replacement of
PropertyModel in some cases. The javadoc leads me to beleave I can do:
public class MyPanel extends Panel {
public MyPanel(String id, IModel model) {
super(id, model);
//add(new Label("label", new PropertyModel(model, "name")));
add(new Label("label", new ComponentPropertyModel("name")));
}
}
..which would have the advantage that the model that is bound to the
component is taken when needed instead of a hard reference to the model
passed in as an argument to the constructor. This would allow the label
to still display the correct value even when myPanel.setModel(..) is
called after constructing MyPanel.
Unfortunately the ComponentPropertyModel always throws an
IllegalStateException because the 'wrapped model' should have been used.
I don't know what that means exactly, but the classes where
ComponentPropertyModel is used call :
super(id);
setModel(wrap(model));
I'm not very in to wrap music, but it seems ComponentPropertyModel is
not doing what I want. What is the intended usage of ComponentPropertyModel?
Of course, the workaround is to not call myPanel.setModel, but
myPanel.setModelObject, so the reference to the component's model is
preserved. That way PropertyModel can be safely used.
Thanks,
Matthijs
--
Matthijs Wensveen
Func. Internet Integration
W http://www.func.nl
T +31 20 4230000
F +31 20 4223500
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: ComponentPropertyModel
Posted by Matthijs Wensveen <m....@func.nl>.
Hi,
CompoundPropertyModel does somewhat of the inverse of what I'm trying to
accomplish.
CompoundPropertyModel binds some model to an expression that is the id
of a component, while ComponentPropertyModel binds the model of the
component that it is used in to some expression. In the first case you
get to choose the model, in the second case you get to choose the
expression. But, alas, it does not work. Now I just use normal
PropertyModels. I could write some ComponentProperyModel as I think it
should work, but no time for that now, unfortunately... :S
As a side note. I don't like using the wicket id's as property
expressions. It places a tight coupling between a component's markup and
the component's model. This may be okay when the model is the component
itself, but not when the model's object is a domain object (which may
change at any time during development. not to speak of changing markup).
Regards,
Matthijs
Maurice Marrink wrote:
> In all my years i have never used the ComponentPropertyModel. I always
> use the CompoundPropertyModel.
> public class MyPanel extends Panel {
> public MyPanel(String id, IModel model) {
> super(id, new CompoundPropertyModel(model));
>
> add(new Label("name"));
> }
> }
>
> Maurice
>
>
> On Tue, Jun 10, 2008 at 2:49 PM, Matthijs Wensveen <m....@func.nl> wrote:
>
>> Hi,
>>
>> I'm trying to use ComponentPropertyModel as a replacement of PropertyModel
>> in some cases. The javadoc leads me to beleave I can do:
>>
>> public class MyPanel extends Panel {
>> public MyPanel(String id, IModel model) {
>> super(id, model);
>>
>> //add(new Label("label", new PropertyModel(model, "name")));
>> add(new Label("label", new ComponentPropertyModel("name")));
>> }
>> }
>>
>> ..which would have the advantage that the model that is bound to the
>> component is taken when needed instead of a hard reference to the model
>> passed in as an argument to the constructor. This would allow the label to
>> still display the correct value even when myPanel.setModel(..) is called
>> after constructing MyPanel.
>> Unfortunately the ComponentPropertyModel always throws an
>> IllegalStateException because the 'wrapped model' should have been used. I
>> don't know what that means exactly, but the classes where
>> ComponentPropertyModel is used call :
>>
>> super(id);
>> setModel(wrap(model));
>>
>> I'm not very in to wrap music, but it seems ComponentPropertyModel is not
>> doing what I want. What is the intended usage of ComponentPropertyModel?
>>
>> Of course, the workaround is to not call myPanel.setModel, but
>> myPanel.setModelObject, so the reference to the component's model is
>> preserved. That way PropertyModel can be safely used.
>>
>> Thanks,
>> Matthijs
>>
>> --
>> Matthijs Wensveen
>> Func. Internet Integration
>> W http://www.func.nl
>> T +31 20 4230000
>> F +31 20 4223500
>>
>> ---------------------------------------------------------------------
>> 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
>
>
--
Matthijs Wensveen
Func. Internet Integration
W http://www.func.nl
T +31 20 4230000
F +31 20 4223500
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: ComponentPropertyModel
Posted by Maurice Marrink <ma...@gmail.com>.
In all my years i have never used the ComponentPropertyModel. I always
use the CompoundPropertyModel.
public class MyPanel extends Panel {
public MyPanel(String id, IModel model) {
super(id, new CompoundPropertyModel(model));
add(new Label("name"));
}
}
Maurice
On Tue, Jun 10, 2008 at 2:49 PM, Matthijs Wensveen <m....@func.nl> wrote:
> Hi,
>
> I'm trying to use ComponentPropertyModel as a replacement of PropertyModel
> in some cases. The javadoc leads me to beleave I can do:
>
> public class MyPanel extends Panel {
> public MyPanel(String id, IModel model) {
> super(id, model);
>
> //add(new Label("label", new PropertyModel(model, "name")));
> add(new Label("label", new ComponentPropertyModel("name")));
> }
> }
>
> ..which would have the advantage that the model that is bound to the
> component is taken when needed instead of a hard reference to the model
> passed in as an argument to the constructor. This would allow the label to
> still display the correct value even when myPanel.setModel(..) is called
> after constructing MyPanel.
> Unfortunately the ComponentPropertyModel always throws an
> IllegalStateException because the 'wrapped model' should have been used. I
> don't know what that means exactly, but the classes where
> ComponentPropertyModel is used call :
>
> super(id);
> setModel(wrap(model));
>
> I'm not very in to wrap music, but it seems ComponentPropertyModel is not
> doing what I want. What is the intended usage of ComponentPropertyModel?
>
> Of course, the workaround is to not call myPanel.setModel, but
> myPanel.setModelObject, so the reference to the component's model is
> preserved. That way PropertyModel can be safely used.
>
> Thanks,
> Matthijs
>
> --
> Matthijs Wensveen
> Func. Internet Integration
> W http://www.func.nl
> T +31 20 4230000
> F +31 20 4223500
>
> ---------------------------------------------------------------------
> 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