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 <ebolw...@worldturner.nl> 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<Boolean> 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<ProductListing> listingRepeater = new
>> RefreshingListView<ProductListing>(
>>                "listing", new
>> PropertyModel<Set<ProductListing>>(getModel(), "listings")) {
>>           �...@override
>>            protected void populateItem(Item<ProductListing> 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<T> extends RefreshingView<T> {
>>
>>    public RefreshingListView(String id) {
>>        super(id);
>>    }
>>
>>    public RefreshingListView(String id, IModel<? extends Collection<T>>
>> model) {
>>        super(id, model);
>>    }
>>
>>   �...@override
>>    protected Iterator<IModel<T>> getItemModels() {
>>        Collection<T> modelObject = getModelObject();
>>        if (modelObject == null) {
>>            modelObject = new ArrayList<T>();
>>        }
>>        return new ModelIteratorAdapter<T>(modelObject.iterator()) {
>>           �...@override
>>            protected IModel<T> model(T object) {
>>                return new CompoundPropertyModel<T>(object);
>>            }
>>        };
>>    }
>>
>>    public Collection<T> getModelObject() {
>>        return getModel().getObject();
>>    }
>>
>>   �...@suppresswarnings("unchecked")
>>    public IModel<List<T>> getModel() {
>>        return (IModel<List<T>>) 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

Reply via email to