Re: Image subclass not getting its model object
Hi Erwin, On Fri, Jun 4, 2010 at 1:03 PM, Erwin Bolwidt wrote: > Hi Ernesto, > > Just got the 1.4.9 source code and I see what you mean. As a rule I always install the source code of any OpenSouce software I use: Javadoc could be wrong or outdated but source code will never mislead you;-) > But why is it like this? > I copied the whole Image source code to a new class, removed this initModel > method, and then things work fine if I don't supply a model. > Sorry Erwin but i don't know why this decision was taken... I just did the same as you did: look into the source code and figured out this was the reason. Maybe some of the core developers can comment on this? Or if you think your use case is a valid one just file a RFE on wicket site. Best, Ernesto - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: Image subclass not getting its model object
I would say you need to use your own image resource, not subclass Image itself. On Fri, Jun 4, 2010 at 7:03 AM, Erwin Bolwidt wrote: > Hi Ernesto, > > Just got the 1.4.9 source code and I see what you mean. > But why is it like this? > I copied the whole Image source code to a new class, removed this initModel > method, and then things work fine if I don't supply a model. > > Why would the Image component behave different from the other components? > This isn't documented in the Javadoc so I didn't expect this, but even then, > what is the need for making Image work differently than others like Label? > > I can think of some usecases where it is fine to display in image that is > derived from some property on a domain object that is accessed with a > CompoundPropertyModel: > > - when you have a Boolean (like here) or Enum-type property and you want to > change the image depending on its value > - when you have want to dynamically generate an image with some text (on top > of a template image), the image is much like a label then > > I can't disable this initModel behavior in a subclass, since you can't call > super.super.initModel, so to disable this behavior, I have to copy the whole > source of the Image class and remove this method. > > That seems like "waste" and you're not benefiting from future improvements > in the Image class then. > > Cheers, > Erwin Bolwidt > > On 6/4/10 9:33 AM, Ernesto Reinaldo Barreiro wrote: >> >> Maybe this is related to this override on Image class? >> >> @Override >> protected IModel initModel() >> { >> // Images don't support Compound models. They either have a >> simple >> // model, explicitly set, or they use their tag's src or >> value >> // attribute to determine the image. >> return null; >> } >> >> Ernesto >> >> >> On Fri, Jun 4, 2010 at 9:30 AM, Erwin Bolwidt >> wrote: >> >>> >>> Oops, I went a bit too far in pruning non-essential code. >>> >>> InStockIconImage has a second constructor: >>> >>> public InStockIconImage(String id) { >>> super(id); >>> } >>> >>> I think it centers around this. If I pass a PropertyModel(listingModel, >>> "inStock") explicitly to the constructor, it works, but not if I depend >>> on >>> the automatic property resolution that works well if I use a Label. >>> >>> How can I get it to work if I don't want to pass a PropertyModel >>> explicitly? >>> >>> Erwin >>> >>> On 6/4/10 9:15 AM, Erwin Bolwidt wrote: >>> Hi, I'm trying to make an image subclass that shows an icon. Which icon it shows depends on its model object, which is a boolean. Problem is, I'm not getting the model object: it's always null. If I use a Label instead of InStockIconImage, it works: the label shows a boolean (true/false). Any idea what could cause this? Thanks, Erwin Here's the icon: public class InStockIconImage extends Image { private static final String PATH_IN_STOCK = "in_stock.png"; private static final String PATH_NOT_IN_STOCK = "not_in_stock.png"; private static final String PATH_NO_MODEL_OBJECT = "empty.png"; public InStockIconImage(String id, IModel model) { super(id, model); } �...@override protected ResourceReference getImageResourceReference() { Boolean inStock = (Boolean) getDefaultModelObject(); String path; if (inStock == null) { path = PATH_NO_MODEL_OBJECT; } else if (inStock) { path = PATH_IN_STOCK; } else { path = PATH_NOT_IN_STOCK; } return new ResourceReference(Icons.class, path); } } Here's how I use it: RefreshingListView listingRepeater = new RefreshingListView( "listing", new PropertyModel>(getModel(), "listings")) { �...@override protected void populateItem(Item item) { item.add(new Label("webShop.name")); item.add(new Label("price")); item.add(new InStockIconImage("inStock")); } }; add(listingRepeater); RefreshingListView is a utility class which decorates a normal RefreshingView: public abstract class RefreshingListView extends RefreshingView { public RefreshingListView(String id) { super(id); } public RefreshingListView(String id, IModel> model) { super(id, model); } �...@override protected Iterator> getItemModels() { Collection modelObject = getModelObject(); if (modelObject == null) { modelObject = new ArrayList(); } return new ModelIteratorAdapter(modelObject.i
Re: Image subclass not getting its model object
Hi Ernesto, Just got the 1.4.9 source code and I see what you mean. But why is it like this? I copied the whole Image source code to a new class, removed this initModel method, and then things work fine if I don't supply a model. Why would the Image component behave different from the other components? This isn't documented in the Javadoc so I didn't expect this, but even then, what is the need for making Image work differently than others like Label? I can think of some usecases where it is fine to display in image that is derived from some property on a domain object that is accessed with a CompoundPropertyModel: - when you have a Boolean (like here) or Enum-type property and you want to change the image depending on its value - when you have want to dynamically generate an image with some text (on top of a template image), the image is much like a label then I can't disable this initModel behavior in a subclass, since you can't call super.super.initModel, so to disable this behavior, I have to copy the whole source of the Image class and remove this method. That seems like "waste" and you're not benefiting from future improvements in the Image class then. Cheers, Erwin Bolwidt On 6/4/10 9:33 AM, Ernesto Reinaldo Barreiro wrote: Maybe this is related to this override on Image class? @Override protected IModel initModel() { // Images don't support Compound models. They either have a simple // model, explicitly set, or they use their tag's src or value // attribute to determine the image. return null; } Ernesto On Fri, Jun 4, 2010 at 9:30 AM, Erwin Bolwidt wrote: Oops, I went a bit too far in pruning non-essential code. InStockIconImage has a second constructor: public InStockIconImage(String id) { super(id); } I think it centers around this. If I pass a PropertyModel(listingModel, "inStock") explicitly to the constructor, it works, but not if I depend on the automatic property resolution that works well if I use a Label. How can I get it to work if I don't want to pass a PropertyModel explicitly? Erwin On 6/4/10 9:15 AM, Erwin Bolwidt wrote: Hi, I'm trying to make an image subclass that shows an icon. Which icon it shows depends on its model object, which is a boolean. Problem is, I'm not getting the model object: it's always null. If I use a Label instead of InStockIconImage, it works: the label shows a boolean (true/false). Any idea what could cause this? Thanks, Erwin Here's the icon: public class InStockIconImage extends Image { private static final String PATH_IN_STOCK = "in_stock.png"; private static final String PATH_NOT_IN_STOCK = "not_in_stock.png"; private static final String PATH_NO_MODEL_OBJECT = "empty.png"; public InStockIconImage(String id, IModel model) { super(id, model); } @Override protected ResourceReference getImageResourceReference() { Boolean inStock = (Boolean) getDefaultModelObject(); String path; if (inStock == null) { path = PATH_NO_MODEL_OBJECT; } else if (inStock) { path = PATH_IN_STOCK; } else { path = PATH_NOT_IN_STOCK; } return new ResourceReference(Icons.class, path); } } Here's how I use it: RefreshingListView listingRepeater = new RefreshingListView( "listing", new PropertyModel>(getModel(), "listings")) { @Override protected void populateItem(Item item) { item.add(new Label("webShop.name")); item.add(new Label("price")); item.add(new InStockIconImage("inStock")); } }; add(listingRepeater); RefreshingListView is a utility class which decorates a normal RefreshingView: public abstract class RefreshingListView extends RefreshingView { public RefreshingListView(String id) { super(id); } public RefreshingListView(String id, IModel> model) { super(id, model); } @Override protected Iterator> getItemModels() { Collection modelObject = getModelObject(); if (modelObject == null) { modelObject = new ArrayList(); } return new ModelIteratorAdapter(modelObject.iterator()) { @Override protected IModel model(T object) { return new CompoundPropertyModel(object); } }; } public Collection getModelObject() { return getModel().getObject(); } @SuppressWarnings("unchecked") public IModel> getModel() { return (IModel>) getDefaultModel(); } } - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: Image subclass not getting its model object
Maybe this is related to this override on Image class? @Override protected IModel initModel() { // Images don't support Compound models. They either have a simple // model, explicitly set, or they use their tag's src or value // attribute to determine the image. return null; } Ernesto On Fri, Jun 4, 2010 at 9:30 AM, Erwin Bolwidt wrote: > Oops, I went a bit too far in pruning non-essential code. > > InStockIconImage has a second constructor: > > public InStockIconImage(String id) { > super(id); > } > > I think it centers around this. If I pass a PropertyModel(listingModel, > "inStock") explicitly to the constructor, it works, but not if I depend on > the automatic property resolution that works well if I use a Label. > > How can I get it to work if I don't want to pass a PropertyModel explicitly? > > Erwin > > On 6/4/10 9:15 AM, Erwin Bolwidt wrote: >> >> Hi, >> >> I'm trying to make an image subclass that shows an icon. Which icon it >> shows depends on its model object, which is a boolean. Problem is, I'm not >> getting the model object: it's always null. If I use a Label instead of >> InStockIconImage, it works: the label shows a boolean (true/false). >> >> Any idea what could cause this? >> >> Thanks, >> Erwin >> >> >> Here's the icon: >> >> public class InStockIconImage extends Image { >> private static final String PATH_IN_STOCK = "in_stock.png"; >> private static final String PATH_NOT_IN_STOCK = "not_in_stock.png"; >> private static final String PATH_NO_MODEL_OBJECT = "empty.png"; >> >> public InStockIconImage(String id, IModel model) { >> super(id, model); >> } >> >> �...@override >> protected ResourceReference getImageResourceReference() { >> Boolean inStock = (Boolean) getDefaultModelObject(); >> String path; >> if (inStock == null) { >> path = PATH_NO_MODEL_OBJECT; >> } else if (inStock) { >> path = PATH_IN_STOCK; >> } else { >> path = PATH_NOT_IN_STOCK; >> } >> return new ResourceReference(Icons.class, path); >> } >> } >> >> Here's how I use it: >> >> RefreshingListView listingRepeater = new >> RefreshingListView( >> "listing", new >> PropertyModel>(getModel(), "listings")) { >> �...@override >> protected void populateItem(Item item) { >> item.add(new Label("webShop.name")); >> item.add(new Label("price")); >> item.add(new InStockIconImage("inStock")); >> } >> }; >> add(listingRepeater); >> >> RefreshingListView is a utility class which decorates a normal >> RefreshingView: >> >> public abstract class RefreshingListView extends RefreshingView { >> >> public RefreshingListView(String id) { >> super(id); >> } >> >> public RefreshingListView(String id, IModel> >> model) { >> super(id, model); >> } >> >> �...@override >> protected Iterator> getItemModels() { >> Collection modelObject = getModelObject(); >> if (modelObject == null) { >> modelObject = new ArrayList(); >> } >> return new ModelIteratorAdapter(modelObject.iterator()) { >> �...@override >> protected IModel model(T object) { >> return new CompoundPropertyModel(object); >> } >> }; >> } >> >> public Collection getModelObject() { >> return getModel().getObject(); >> } >> >> �...@suppresswarnings("unchecked") >> public IModel> getModel() { >> return (IModel>) getDefaultModel(); >> } >> >> } >> >> >> - >> 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 > > - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: Image subclass not getting its model object
Oops, I went a bit too far in pruning non-essential code. InStockIconImage has a second constructor: public InStockIconImage(String id) { super(id); } I think it centers around this. If I pass a PropertyModel(listingModel, "inStock") explicitly to the constructor, it works, but not if I depend on the automatic property resolution that works well if I use a Label. How can I get it to work if I don't want to pass a PropertyModel explicitly? Erwin On 6/4/10 9:15 AM, Erwin Bolwidt wrote: Hi, I'm trying to make an image subclass that shows an icon. Which icon it shows depends on its model object, which is a boolean. Problem is, I'm not getting the model object: it's always null. If I use a Label instead of InStockIconImage, it works: the label shows a boolean (true/false). Any idea what could cause this? Thanks, Erwin Here's the icon: public class InStockIconImage extends Image { private static final String PATH_IN_STOCK = "in_stock.png"; private static final String PATH_NOT_IN_STOCK = "not_in_stock.png"; private static final String PATH_NO_MODEL_OBJECT = "empty.png"; public InStockIconImage(String id, IModel model) { super(id, model); } @Override protected ResourceReference getImageResourceReference() { Boolean inStock = (Boolean) getDefaultModelObject(); String path; if (inStock == null) { path = PATH_NO_MODEL_OBJECT; } else if (inStock) { path = PATH_IN_STOCK; } else { path = PATH_NOT_IN_STOCK; } return new ResourceReference(Icons.class, path); } } Here's how I use it: RefreshingListView listingRepeater = new RefreshingListView( "listing", new PropertyModel>(getModel(), "listings")) { @Override protected void populateItem(Item item) { item.add(new Label("webShop.name")); item.add(new Label("price")); item.add(new InStockIconImage("inStock")); } }; add(listingRepeater); RefreshingListView is a utility class which decorates a normal RefreshingView: public abstract class RefreshingListView extends RefreshingView { public RefreshingListView(String id) { super(id); } public RefreshingListView(String id, IModelCollection> model) { super(id, model); } @Override protected Iterator> getItemModels() { Collection modelObject = getModelObject(); if (modelObject == null) { modelObject = new ArrayList(); } return new ModelIteratorAdapter(modelObject.iterator()) { @Override protected IModel model(T object) { return new CompoundPropertyModel(object); } }; } public Collection getModelObject() { return getModel().getObject(); } @SuppressWarnings("unchecked") public IModel> getModel() { return (IModel>) getDefaultModel(); } } - 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
Image subclass not getting its model object
Hi, I'm trying to make an image subclass that shows an icon. Which icon it shows depends on its model object, which is a boolean. Problem is, I'm not getting the model object: it's always null. If I use a Label instead of InStockIconImage, it works: the label shows a boolean (true/false). Any idea what could cause this? Thanks, Erwin Here's the icon: public class InStockIconImage extends Image { private static final String PATH_IN_STOCK = "in_stock.png"; private static final String PATH_NOT_IN_STOCK = "not_in_stock.png"; private static final String PATH_NO_MODEL_OBJECT = "empty.png"; public InStockIconImage(String id, IModel model) { super(id, model); } @Override protected ResourceReference getImageResourceReference() { Boolean inStock = (Boolean) getDefaultModelObject(); String path; if (inStock == null) { path = PATH_NO_MODEL_OBJECT; } else if (inStock) { path = PATH_IN_STOCK; } else { path = PATH_NOT_IN_STOCK; } return new ResourceReference(Icons.class, path); } } Here's how I use it: RefreshingListView listingRepeater = new RefreshingListView( "listing", new PropertyModel>(getModel(), "listings")) { @Override protected void populateItem(Item item) { item.add(new Label("webShop.name")); item.add(new Label("price")); item.add(new InStockIconImage("inStock")); } }; add(listingRepeater); RefreshingListView is a utility class which decorates a normal RefreshingView: public abstract class RefreshingListView extends RefreshingView { public RefreshingListView(String id) { super(id); } public RefreshingListView(String id, IModelCollection> model) { super(id, model); } @Override protected Iterator> getItemModels() { Collection modelObject = getModelObject(); if (modelObject == null) { modelObject = new ArrayList(); } return new ModelIteratorAdapter(modelObject.iterator()) { @Override protected IModel model(T object) { return new CompoundPropertyModel(object); } }; } public Collection getModelObject() { return getModel().getObject(); } @SuppressWarnings("unchecked") public IModel> getModel() { return (IModel>) getDefaultModel(); } } - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org