You might be running into a sequencing problem e.g. the component is
being created prior to the assets, hence you're getting a null here. Why not
just get the asset during the render method of the component? Not sure
that'll work, but there's really no reason your logic has to be in the
constructor so I'd definitely try moving it to render.

        --- Pat

> -----Original Message-----
> From: news [mailto:[EMAIL PROTECTED] On Behalf Of Dirk Dittert
> Sent: Sunday, July 10, 2005 3:10 AM
> To: [email protected]
> Subject: Resource loading question
> 
> Hi,
> 
> I am trying to create a component right now that requires an asset. The
> asset is properly specified as a context-asset in the .jwc file.
> 
> I wanted to keep a reference to the image in a static variable because
> it does not change. However, I can't load the image in the
> constructor...
> 
> public class HomeLink extends AbstractComponent {
>     private static IAsset image;
> 
>     public HomeLink() {
>         super();
>         if (image == null) {
>             image = getAsset("menuImage");
>                 // image is always null at this point!
>         }
>     }
> 
>     protected void renderComponent(IMarkupWriter w, IRequestCycle c) {
>         image = getAsset("menuImage");
>         // asset is properly loaded
>     }
> }
> 
> My question now is, what is the proper way to load assets?
> 
> - implement a PageRenderListener that does the initialization (would it
>   be called for a component?)
> 
> - initialize the asset in the renderComponent method?
> 
> - not store the reference for the asset at all (maybe the assets are
>   internally cached anyway)?
> 
> Best,
> 
> Dirk Dittert
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to