You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@wicket.apache.org by Vincent Demay <vi...@anyware-tech.com> on 2007/07/05 18:50:29 UTC
IComponentInheritedModel & IWrapModel just to get the component in
model
Hi
I have a custom model where i need to access to the component. The only
method I found seems me a little bit overkill :
my model should implement IComponentInheritedModel and I also need to
declare a new class implementing IWrapModel to return on
wrapOnInheritance. Furthermore all this stuff is not really oriented to
simply get the component in the model. (maybe there is a better way?)
I thought about a very simple way :
Just creating a new interface :
IComponentAwareModel{ void setComponent(Component component)}
and adding in component.class
if (model instanceof IComponentAwareModel){
((IComponentAwareModel)model.setComponent(this))}
I think it also avoid to write 40 code lines just to get the component
in the model.
WDYT?
--
Vincent Demay
Re: IComponentInheritedModel & IWrapModel just to get the component in model
Posted by Matej Knopp <ma...@gmail.com>.
Perhaps you are looking for IComponentAssignedModel ?
-Matej
On 7/5/07, Jean-Baptiste Quenot <jb...@apache.org> wrote:
> * Vincent Demay:
>
> > I think it also avoid to write 40 code lines just to get the
> > component in the model.
>
> I also find it utterly complicated. Is there a reason for this
> that we are overlooking?
> --
> Jean-Baptiste Quenot
> aka John Banana Qwerty
> http://caraldi.com/jbq/
>
Re: IComponentInheritedModel & IWrapModel just to get the component in model
Posted by Igor Vaynberg <ig...@gmail.com>.
On 7/5/07, Jean-Baptiste Quenot <jb...@apache.org> wrote:
>
> * Vincent Demay:
>
> > I think it also avoid to write 40 code lines just to get the
> > component in the model.
>
> I also find it utterly complicated. Is there a reason for this
> that we are overlooking?
> --
yes, there is. the interface you are proposing would only support a single
model instance per component relationship, where in reality it is often the
case that a single instance of imodel is assigned to multiple components.
-igor
Jean-Baptiste Quenot
> aka John Banana Qwerty
> http://caraldi.com/jbq/
>
Re: IComponentInheritedModel & IWrapModel just to get the component in model
Posted by Jean-Baptiste Quenot <jb...@apache.org>.
* Vincent Demay:
> I think it also avoid to write 40 code lines just to get the
> component in the model.
I also find it utterly complicated. Is there a reason for this
that we are overlooking?
--
Jean-Baptiste Quenot
aka John Banana Qwerty
http://caraldi.com/jbq/
Re: IComponentInheritedModel & IWrapModel just to get the component in model
Posted by Johan Compagner <jc...@gmail.com>.
make your own base model
public abstract class ComponentAssignModel implements IWrapModel,
IComponentAssignedModel
{
private Component component;
/**
* @see org.apache.wicket.model.IWrapModel#getWrappedModel()
*/
public IModel getWrappedModel()
{
return this;
}
/**
* @see org.apache.wicket.model.IComponentAssignedModel#wrapOnAssignment
(org.apache.wicket.Component)
*/
public IWrapModel wrapOnAssignment(Component component)
{
this.component = component;
return this;
}
protected Component getComponent()
{
return this.component;
}
}
the only thing is that i dont know if this completely works correctly (but i
think it should, bug or no bugs)
johan
On 7/5/07, Vincent Demay <vi...@anyware-tech.com> wrote:
>
> Hi
>
> I have a custom model where i need to access to the component. The only
> method I found seems me a little bit overkill :
> my model should implement IComponentInheritedModel and I also need to
> declare a new class implementing IWrapModel to return on
> wrapOnInheritance. Furthermore all this stuff is not really oriented to
> simply get the component in the model. (maybe there is a better way?)
>
> I thought about a very simple way :
> Just creating a new interface :
> IComponentAwareModel{ void setComponent(Component component)}
> and adding in component.class
> if (model instanceof IComponentAwareModel){
> ((IComponentAwareModel)model.setComponent(this))}
>
> I think it also avoid to write 40 code lines just to get the component
> in the model.
>
> WDYT?
>
> --
> Vincent Demay
>
>
>