You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by jy <jy...@gmail.com> on 2007/12/12 23:21:23 UTC

accessing parent model from child component -- redundant markup element using same field

Hello.

A newbie here.
Is there a way for a child component to get access to the model added
to the parent component?  I have two labels in the child component
that use the same model field.  Since each label requires unique id, I
can't use CompoundPropertyModel, can i?  I saw the example with
BoundCompoundPropertyModel, but that needs access to the model.  So
how can i get the model that was added to the parent?

I stepped into child component in debugger.  Both getParent() and
getModel() return null.

Thanks in advance,
J

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


Re: accessing parent model from child component -- redundant markup element using same field

Posted by Igor Vaynberg <ig...@gmail.com>.
how exactly does this break encapsulaton?

the only drawback to providing the model if you dont use it is that
you have to store a reference to it.

-igor


On Dec 12, 2007 3:36 PM, jy <jy...@gmail.com> wrote:
> Great.  Thx.
>
> I also "resolved" this problem by using the constructor that takes
> model as the second argument.
>
> It seems both approaches remove encapsulation.  i.e. The parent must
> know ahead of time that child needs the handle to the model, and must
> provide explicitly.
>
> Is there any drawback (in terms of performance, resource usage, etc)
> for providing the model to the child regardless it needs it or not?
>
> --JY
>
>
>
>
> On Dec 12, 2007 2:59 PM, Igor Vaynberg <ig...@gmail.com> wrote:
> > add(new Label("label") {
> > protected IModel initModel() { return getParent().getModel(); }
> > });
> >
> > -igor
> >
> >
> > On Dec 12, 2007 2:21 PM, jy <jy...@gmail.com> wrote:
> > > Hello.
> > >
> > > A newbie here.
> > > Is there a way for a child component to get access to the model added
> > > to the parent component?  I have two labels in the child component
> > > that use the same model field.  Since each label requires unique id, I
> > > can't use CompoundPropertyModel, can i?  I saw the example with
> > > BoundCompoundPropertyModel, but that needs access to the model.  So
> > > how can i get the model that was added to the parent?
> > >
> > > I stepped into child component in debugger.  Both getParent() and
> > > getModel() return null.
> > >
> > > Thanks in advance,
> > > J
> > >
> > > ---------------------------------------------------------------------
> > > 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
> >
> >
>
> ---------------------------------------------------------------------
> 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


Re: accessing parent model from child component -- redundant markup element using same field

Posted by jy <jy...@gmail.com>.
Great.  Thx.

I also "resolved" this problem by using the constructor that takes
model as the second argument.

It seems both approaches remove encapsulation.  i.e. The parent must
know ahead of time that child needs the handle to the model, and must
provide explicitly.

Is there any drawback (in terms of performance, resource usage, etc)
for providing the model to the child regardless it needs it or not?

--JY



On Dec 12, 2007 2:59 PM, Igor Vaynberg <ig...@gmail.com> wrote:
> add(new Label("label") {
> protected IModel initModel() { return getParent().getModel(); }
> });
>
> -igor
>
>
> On Dec 12, 2007 2:21 PM, jy <jy...@gmail.com> wrote:
> > Hello.
> >
> > A newbie here.
> > Is there a way for a child component to get access to the model added
> > to the parent component?  I have two labels in the child component
> > that use the same model field.  Since each label requires unique id, I
> > can't use CompoundPropertyModel, can i?  I saw the example with
> > BoundCompoundPropertyModel, but that needs access to the model.  So
> > how can i get the model that was added to the parent?
> >
> > I stepped into child component in debugger.  Both getParent() and
> > getModel() return null.
> >
> > Thanks in advance,
> > J
> >
> > ---------------------------------------------------------------------
> > 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
>
>

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


Re: accessing parent model from child component -- redundant markup element using same field

Posted by Igor Vaynberg <ig...@gmail.com>.
add(new Label("label") {
protected IModel initModel() { return getParent().getModel(); }
});

-igor

On Dec 12, 2007 2:21 PM, jy <jy...@gmail.com> wrote:
> Hello.
>
> A newbie here.
> Is there a way for a child component to get access to the model added
> to the parent component?  I have two labels in the child component
> that use the same model field.  Since each label requires unique id, I
> can't use CompoundPropertyModel, can i?  I saw the example with
> BoundCompoundPropertyModel, but that needs access to the model.  So
> how can i get the model that was added to the parent?
>
> I stepped into child component in debugger.  Both getParent() and
> getModel() return null.
>
> Thanks in advance,
> J
>
> ---------------------------------------------------------------------
> 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