[ 
https://issues.apache.org/jira/browse/WICKET-974?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12527448
 ] 

Peter Ertl commented on WICKET-974:
-----------------------------------

Well, I was wrong (thanks gerolf)

localizedImageResource is never null so the better approach would be to provide 
non-null getters for 

protected Resource getImageResource()
protected ResourceReference getImageResourceReference() 

I will attach a patch...

> Image#getResource always returns null even if there is a resource
> -----------------------------------------------------------------
>
>                 Key: WICKET-974
>                 URL: https://issues.apache.org/jira/browse/WICKET-974
>             Project: Wicket
>          Issue Type: Bug
>          Components: wicket
>            Reporter: Peter Ertl
>         Attachments: image.patch
>
>
> When trying to implement a subclass of org.apache.wicket.markup.html.image 
> that automatically shows/hides (using isVisible) depending on if there is 
> image data to show I stumbled upon the following:
>       /**
>        * @return Resource returned from subclass
>        */
>       protected Resource getImageResource()
>       {
>               return null;
>       }
> the same for
>       /**
>        * @return ResourceReference returned from subclass
>        */
>       protected ResourceReference getImageResourceReference()
>       {
>               return null;
>       }
> this is confusing and the javadoc should be more verbose on the intention 
> that caused this design.
> due to the fact that 
>    
>   private final LocalizedImageResource localizedImageResource = new 
> LocalizedImageResource(this);
> is private and not protected there is no way except overriding all the setters
>       public void setImageResource(final Resource imageResource)
>       public void setImageResourceReference(final ResourceReference 
> resourceReference)
>       public void setImageResourceReference(final ResourceReference 
> resourceReference, final ValueMap parameters)
>       public Component setModel(IModel model)
> to detect if the image is 'blank' (having no src attribute) or has some data.
> I think it would make sense to add
>   protected final LocalizedImageResource getLocalizedImageResource()
>   {
>     return this.localizedImageResource;
>   }
> So it's easy to implement something like this:
>   Image imageTag = new Image("test")
>     {
>       public boolean isVisible()
>       {
>         return getLocalizedImageResource() != null;
>       }
>   };
>   add(imageTag);
>   if(database.has.image.for.product)
>   {
>     imageTag.setImageResource(......);
>   }
>   // if product has no image the image tag is not rendered

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to