You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Stefan Renz <s....@efonds.com> on 2013/07/16 22:53:42 UTC

How to hide an optional Image component?

Hi guys,

I'm desparate for your help: I just can't figure out how to suppress an
Image in case its IResource yields nothing.

Here's some context:

A customer may have a custom logo image (in fact, there's some logic
involved in determining which exact logo to use, but that's beside the
point) located in some database. Using Wicket's Image component, I
figured I would need to implement the logo resolution algorithm and
loading from the DB with either subclassing DynamicImageResource, or
subclassing AbstractResourceStream (which is more approriate?).

Works fine if a logo is there -- the image shows up. However, if there
_is_ no logo, the browser (firefox in my case) renders a question mark
instead of showing nothing. Both returning null or an empty byte array
doesn't matter.

I usually suppress a component with a behavior, or within the
#onConfigure()-Method, but in the Image's case, where I only have an
IResource or ResourceReference, I just don't have a hint on how to
determine if the image data is there or not (apart from asking the
database _again_ for the data or presence thereof).

Any ideas? What method/class have I missed? Where should I look?

Thanks for your help.
Cheers
    Stefan


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


Re: How to hide an optional Image component?

Posted by Stefan Renz <s....@efonds.com>.
Hello,

just to tie up loose ends -- here's the solution I decided on:

First, a Model encapsulates the logic and DB-access for a Logo object. I
can pass this into a LogoResource (extends DynamicImageResource), which
streams out the data from that Model's object. The model, however, also
serves to show or hide the Image component using that Resource.

Thanks for your time and suggestions.
Bye
    Stefan

Stefan Renz wrote:
> Hi guys,
> 
> I'm desparate for your help: I just can't figure out how to suppress an
> Image in case its IResource yields nothing.
> 
> Here's some context:
> 
> A customer may have a custom logo image (in fact, there's some logic
> involved in determining which exact logo to use, but that's beside the
> point) located in some database. Using Wicket's Image component, I
> figured I would need to implement the logo resolution algorithm and
> loading from the DB with either subclassing DynamicImageResource, or
> subclassing AbstractResourceStream (which is more approriate?).
> 
> Works fine if a logo is there -- the image shows up. However, if there
> _is_ no logo, the browser (firefox in my case) renders a question mark
> instead of showing nothing. Both returning null or an empty byte array
> doesn't matter.
> 
> I usually suppress a component with a behavior, or within the
> #onConfigure()-Method, but in the Image's case, where I only have an
> IResource or ResourceReference, I just don't have a hint on how to
> determine if the image data is there or not (apart from asking the
> database _again_ for the data or presence thereof).
> 
> Any ideas? What method/class have I missed? Where should I look?
> 
> Thanks for your help.
> Cheers
>     Stefan
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 

-- 
im Auftrag der eFonds Solutions AG, +49-89-579494-3417


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


Re: How to hide an optional Image component?

Posted by Cedric Gatay <ga...@gmail.com>.
Hi,
a workaround could be returning an empty 1px*1px image from your IResource.
This way browsers won't complain with invalid content as you encounter.

Regards,

__
Cedric Gatay (@Cedric_Gatay <http://twitter.com/Cedric_Gatay>)
http://code-troopers.com | http://www.bloggure.info | http://cedric.gatay.fr


On Tue, Jul 16, 2013 at 10:53 PM, Stefan Renz <s....@efonds.com> wrote:

> Hi guys,
>
> I'm desparate for your help: I just can't figure out how to suppress an
> Image in case its IResource yields nothing.
>
> Here's some context:
>
> A customer may have a custom logo image (in fact, there's some logic
> involved in determining which exact logo to use, but that's beside the
> point) located in some database. Using Wicket's Image component, I
> figured I would need to implement the logo resolution algorithm and
> loading from the DB with either subclassing DynamicImageResource, or
> subclassing AbstractResourceStream (which is more approriate?).
>
> Works fine if a logo is there -- the image shows up. However, if there
> _is_ no logo, the browser (firefox in my case) renders a question mark
> instead of showing nothing. Both returning null or an empty byte array
> doesn't matter.
>
> I usually suppress a component with a behavior, or within the
> #onConfigure()-Method, but in the Image's case, where I only have an
> IResource or ResourceReference, I just don't have a hint on how to
> determine if the image data is there or not (apart from asking the
> database _again_ for the data or presence thereof).
>
> Any ideas? What method/class have I missed? Where should I look?
>
> Thanks for your help.
> Cheers
>     Stefan
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: How to hide an optional Image component?

Posted by Stefan Renz <s....@efonds.com>.
Hi Sven,

Sven Meier wrote:
>> apart from asking the database _again_ for the data or presence thereof
> 
> Whether the image is visible must be determined when the page is
> rendered. The actual loading of the image is done in another request.
> Thus two times to ask the databse.

thanks for reminding me -- sometimes, a powerful framework such as
Wicket makes you forget you work with HTTP ;-)

> 
> Alternatively you may render a default resource (e.g.
> https://www.google.com/search?q=no+image) if your database doesn't have
> any data to stream back when the image is requested.
> 
> Regards
> Sven
> 

Have a nice day.
    Stefan

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


Re: How to hide an optional Image component?

Posted by Sven Meier <sv...@meiers.net>.
> apart from asking the database _again_ for the data or presence thereof

Whether the image is visible must be determined when the page is rendered. The actual loading of the image is done in another request. Thus two times to ask the databse.

Alternatively you may render a default resource (e.g. https://www.google.com/search?q=no+image) if your database doesn't have any data to stream back when the image is requested.

Regards
Sven


On 07/16/2013 10:53 PM, Stefan Renz wrote:
> Hi guys,
>
> I'm desparate for your help: I just can't figure out how to suppress an
> Image in case its IResource yields nothing.
>
> Here's some context:
>
> A customer may have a custom logo image (in fact, there's some logic
> involved in determining which exact logo to use, but that's beside the
> point) located in some database. Using Wicket's Image component, I
> figured I would need to implement the logo resolution algorithm and
> loading from the DB with either subclassing DynamicImageResource, or
> subclassing AbstractResourceStream (which is more approriate?).
>
> Works fine if a logo is there -- the image shows up. However, if there
> _is_ no logo, the browser (firefox in my case) renders a question mark
> instead of showing nothing. Both returning null or an empty byte array
> doesn't matter.
>
> I usually suppress a component with a behavior, or within the
> #onConfigure()-Method, but in the Image's case, where I only have an
> IResource or ResourceReference, I just don't have a hint on how to
> determine if the image data is there or not (apart from asking the
> database _again_ for the data or presence thereof).
>
> Any ideas? What method/class have I missed? Where should I look?
>
> Thanks for your help.
> Cheers
>      Stefan
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>


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