Hi Sam,

I think your use of Item#setModel() and Component#initModel() are
unconventional. Try:

populateItem(Item<Post> item) {
item.add(new ProductPanel("product", item.getModel());
}

ProductPanel(String id, IModel<Product> model) {
super(id, CompoundPropertyModel.of(model));
add(new Label("name"));
add(new Label("condition"));
}

On Fri, Feb 3, 2012 at 12:51 PM, Sam Barrow <[email protected]> wrote:

> Hi guys,
>
> I'm having an issue with property models.
>
> I have a DataView running over a number of Post objects. The Post object
> has a property named "product" with appropriate getter/setter.
>
> new DataView<Post>("posts", provider) {
>  protected void populateItem(final Item<Post> item) {
>    item.setModel(CompoundPropertyModel.of(item.getModel()));
>    item.add(new ProductPanel("product"));
>  }
> }
>
> The issue is within ProductPanel. It has a number of labels, each only
> specifying a name (no model). In my initModel() I am creating a
> CompoundPropertyModel around super.initModel(). I was expecting it to
> pull these properties from the model object of my ProductPanel.
>
> public class ProductPanel extends GenericPanel<Product> {
>  public ProductPanel(final String id) {
>    add(new Label("name"));
>    add(new Label("condition"));
>  }
>  protected IModel<?> initModel() {
>    return CompoundPropertyModel.of(super.initModel());
>  }
> }
>
> But I get this error: org.apache.wicket.WicketRuntimeException: No get
> method defined for class: class com.cellcycleusa.domain.Post expression:
> name.
>
> Seems that it's trying to access the Post object from the DataView to
> pull the property from, not the model object of the ProductPanel itself.
>
> Now the really funny part is that if I just add this to ProductPanel,
> everything works fine:
>
> protected void onBeforeRender() {
>  getModel();
>  super.onBeforeRender();
> }
>
> Or if I specify the model objects for the labels within ProductPanel
> like this:
>
> new Label("name", new ComponentPropertyModel<String>("name"))
>
> That works as well.
>
> What am I doing wrong?
>
> --
>
> Sam Barrow
> Squidix IT Services
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>

Reply via email to