Forwarded to dev.

In my example below, I tried specifying ComponentPropertyModel as the model of SmallComponent, but when I tried to wrap it in CompoundPropertyModel, the code threw an error at runtime because ComponentPropertyModel implements IComponentAssignedModel. I had to call Component.wrap with the ComponentPropertyModel first.

Actually this seems to work fairly well. The initModel method is invoked when a model is actually needed rather than when it might be needed (for example because it might be a IComponentAssignedModel, but will be ignored if it's not). Explicitly passing ComponentPropertyModel to SmallComponent causes it to have a model that the child's initModel method can find later.

On the other hand, it would be nice to simplify IComponentAssignedModel, IComponentInheritedModel, and IWrapModel in some way. I work with a number of Wicket users, and one of the biggest challenges they have is figuring out how to use all the various models effectively. Having models that have unique interactions with Component makes it that much more difficult for them. I'll think about it and post something later.

Regards,
W


Begin forwarded message:

From: Igor Vaynberg <[email protected]>
Date: February 15, 2009 11:50:47 PM EST
To: [email protected]
Subject: Re: N-level CompoundPropertyModel
Reply-To: [email protected]

hrm, looks like johan changed it here

526472  4/7/07 12:13 PM 3       jcompagner      component initModel will not 
call
getModel on the parent, but will directly use the field (so that not
all kinds of inbetween models are created) if model is an iwrapmodel
and the wrapped modes is an inherited one then the model will be
cleared on detach Compound.getTarget() removed. Compound will not
unwrap in getObject() anymore AbstractPropertyModel will unwrap until
all models are processed

seems to me that the change breaks what i thought the contract of
initmodel was... we should discuss on dev, mind sending a message?

-igor


On Sun, Feb 15, 2009 at 10:08 AM, Willis Blackburn <[email protected]> wrote:
Igor,

Are you sure that will work? I don't think that SmallComponent's initModel method is ever called, because when the Label that is part of SmallComponent
is searching for a model (in Component.initModel), it invokes the
getModelImpl method of SmallComponent, which doesn't call initModel. (The comment in the code says "Don't call getModel() that could initialize many
in-between useless models."

W

On Feb 15, 2009, at 12:23 PM, Igor Vaynberg wrote:

public class smallcomponent extends component {
protected imodel initmodel() {
   imodel model=super.initmodel();
   return new compoundpropertymodel(model);
}
}

-igor

On Sun, Feb 15, 2009 at 8:19 AM, Willis Blackburn <[email protected]>
wrote:

Hello,

I have a situation that keeps coming up. All of my solutions have seemed clumsy, which makes me think that there's a better way of approaching
this
that I just haven't figured out.  Can someone point me in the right
direction?

What I want is to have a Page that uses CompoundPropertyModel, and then include a component on that page that also uses CompoundPropertyModel.
So
roughly it looks like this:

public class BigObject {
public SmallObject get SmallObject() { ... }
}

public class SmallObject {
public String getName() { ... }
}

public class BigPage {
public BigPage(BigObject object) {
    setModel(new CompoundPropertyModel(object));
    add(new SmallComponent("smallObject"));
}
}

public class SmallComponent {
public SmallComponent() {
    add(new Label("name"));
}
}

If I try to do just this, then I get an error because the label that's
part
of SmallComponent finds the BigPage model and fails because there's no
property of BigObject called name.

So obviously SmallComponent needs some model:

public class SmallComponent {
public SmallComponent(IModel model) {
    setModel(new CompoundPropertyModel(model));
    add(new Label("name"));
}
}

But what model to give it?  I tried passing it new
ComponentPropertyModel("smallObject"), which didn't work because
ComponentPropertyModel implements IComponentAssignedModel and thus can't
be
directly wrapped in CompoundPropertyModel. Adding a call to wrap() in
the
SmallComponent constructor fixed the problem, but I'm not sure if I can
just
call wrap and carry on or if there will be some unforeseen consequence of
that down the road.  Is there a standard way of doing this?

Thanks,
Willis


---------------------------------------------------------------------
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]



---------------------------------------------------------------------
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]


Reply via email to