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 <[EMAIL PROTECTED]> 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: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]