Re: Property Model Issue

2012-02-04 Thread James Carman
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(ItemPost item) {
  item.add(new ProductPanel(product, item.getModel());
  }
 
  ProductPanel(String id, IModelProduct 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(ItemPost item) {
  item.add(new ProductPanel(product, new
 PropertyModelProduct(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 DataViewPost(posts, provider) {
protected void populateItem(final ItemPost 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 GenericPanelProduct {
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 ComponentPropertyModelString(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




Re: Property Model Issue

2012-02-04 Thread Sam Barrow

On Sat, 2012-02-04 at 10:27 -0500, James Carman wrote:
 I would avoid cpms like the plague.  Too much magic.
 On Feb 3, 2012 5:12 PM, Sam Barrow s...@sambarrow.com wrote:
 

Yeah, I know what you mean. I usually try to avoid them, I'm not too
fond of runtime reflection, loss of compile time type checking, etc. At
the same time though there is something to be said for doing things the
conventional way within a framework, and from everything I've seen this
is it.

I actually figured out the problem. When wicket tries to initModel it
searches parent components for their model, but it doesn't use getModel,
it uses getModelImpl, which does none of initModel magic. In effect,
it's incapable of handling chains of nested models in which more than
two links in a row are not manually specified.



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



Re: Property Model Issue

2012-02-04 Thread James Carman
I wouldn't necessarily say that CPMs are the wicket way.

On Sat, Feb 4, 2012 at 11:32 AM, Sam Barrow s...@sambarrow.com wrote:

 On Sat, 2012-02-04 at 10:27 -0500, James Carman wrote:
 I would avoid cpms like the plague.  Too much magic.
 On Feb 3, 2012 5:12 PM, Sam Barrow s...@sambarrow.com wrote:


 Yeah, I know what you mean. I usually try to avoid them, I'm not too
 fond of runtime reflection, loss of compile time type checking, etc. At
 the same time though there is something to be said for doing things the
 conventional way within a framework, and from everything I've seen this
 is it.

 I actually figured out the problem. When wicket tries to initModel it
 searches parent components for their model, but it doesn't use getModel,
 it uses getModelImpl, which does none of initModel magic. In effect,
 it's incapable of handling chains of nested models in which more than
 two links in a row are not manually specified.



 -
 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



Property Model Issue

2012-02-03 Thread Sam Barrow
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 DataViewPost(posts, provider) {
  protected void populateItem(final ItemPost 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 GenericPanelProduct {
  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 ComponentPropertyModelString(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



Re: Property Model Issue

2012-02-03 Thread Dan Retzlaff
Hi Sam,

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

populateItem(ItemPost item) {
item.add(new ProductPanel(product, item.getModel());
}

ProductPanel(String id, IModelProduct 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 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 DataViewPost(posts, provider) {
  protected void populateItem(final ItemPost 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 GenericPanelProduct {
  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 ComponentPropertyModelString(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




Re: Property Model Issue

2012-02-03 Thread Dan Retzlaff
I seem to have confused your data model. How do you get from Post to
Product?

On Fri, Feb 3, 2012 at 1:57 PM, Dan Retzlaff dretzl...@gmail.com wrote:

 Hi Sam,

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

 populateItem(ItemPost item) {
 item.add(new ProductPanel(product, item.getModel());
 }

 ProductPanel(String id, IModelProduct 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 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 DataViewPost(posts, provider) {
  protected void populateItem(final ItemPost 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 GenericPanelProduct {
  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 ComponentPropertyModelString(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





Re: Property Model Issue

2012-02-03 Thread Sam Barrow

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(ItemPost item) {
 item.add(new ProductPanel(product, item.getModel());
 }
 
 ProductPanel(String id, IModelProduct 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(ItemPost item) {
 item.add(new ProductPanel(product, new
PropertyModelProduct(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 DataViewPost(posts, provider) {
   protected void populateItem(final ItemPost 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 GenericPanelProduct {
   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 ComponentPropertyModelString(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