I would avoid cpms like the plague.  Too much "magic".
On Feb 3, 2012 5:12 PM, "Sam Barrow" <s...@sambarrow.com> wrote:

>
> On Fri, 2012-02-03 at 13:57 -0800, Dan Retzlaff wrote:
> > Hi Sam,
> >
> > I think your use of Item#setModel() and Component#initModel() are
> > unconventional. Try:
> >
>
> Hi Dan,
>
> Yes I never really liked my item.setModel() technique, just didn't seem
> right to me but I've seen it in more than one tutorial so I figured it
> was the way it was done. I actually moved the compounding part over the
> newItem method in dataview just now though, seems cleaner.
>
> > 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"));
> > }
> >
>
> I'm sure this would work, just wondering if there's a better way to do
> this? Is it good practice to manipulate the model in the constructor
> like that? Doesn't seem right to me as the model may need to change
> (maybe via ajax?). I try to never mess with my models like that outside
> of the rendering phase. I've been toying with wicket occasionally for
> over a year now, but never gone this far with it so I'm still learning
> how it all works.
>
> I would if at all possible like to retain the ability to create a new
> ProductPanel without specifying the model in the constructor. This seems
> to be the way things are usually done in Wicket so I figured there must
> be a better way.
>
> Product is a property of post so I'd be specifying it in two different
> places, and again if I wanted to add any more composited components
> under ProductPanel.
>
> I've corrected your code to reflect this (I just got your next message).
>
> > populateItem(Item<Post> item) {
> > item.add(new ProductPanel("product", new
> PropertyModel<Product>(item.getModel(), "product"));
> > }
> >
>
> I was using the compoundpropertymodel to avoid specifying the product
> property manually as is done above, but that part is working for me with
> no issues, it's just inside ProductPanel that I'm having problems.
>
> It's not that I'm really that lazy, just an issue of best practice for
> me.
>
> > On Fri, Feb 3, 2012 at 12:51 PM, Sam Barrow <s...@sambarrow.com> 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: users-unsubscr...@wicket.apache.org
> > > For additional commands, e-mail: users-h...@wicket.apache.org
> > >
> > >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
> For additional commands, e-mail: users-h...@wicket.apache.org
>
>

Reply via email to