You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Kevin Menard <km...@servprise.com> on 2005/10/04 20:15:30 UTC

Re: Creating an IAsset in code from a context image

On Mon, 05 Sep 2005 10:03:09 -0400, Joe Trewin <jo...@canfactory.com> wrote:

> For anyone else trying to do something similar, I eventually solved this
> by doing the following:
>
> 	ContextResource resource = new ContextResource(servletContext,
> "myfile.gif");
> 	IAsset asset = new ContextAsset("images/", resource,
> component.getLocation());

I'm pretty sure this will only work if you map your servlet to the root  
context.  If you want the actual context name, then you need to inject the  
WebRequest object too and call getContextPath() on that.

> This seems to me to be a slightly long-winded way of getting hold of the
> context, especially as it's required for creating ContextResources, and
> I'm not sure I like the idea of calling getSession() when I'm not doing
> session-related things (and I don't want a session created most of the
> time).
>
> Am I doing this correctly, or is there (or should there be) a better way
> of getting handles to things like this?

I haven't found a better way to doing it, but I agree wholeheartedly with  
you.  In fact, I had no idea how to do this until reading this thread.   
Part of the problem is that it relies on the HiveMind API, which I could  
not find the javadocs too online (they are in the documenation download  
though).  I really don't mind having to use HiveMind with Tapestry 4, but  
having to know the HiveMind API too is a lot to ask of people I think.

In any event, it would be really nice if the framework helped out here.   
Inject the ServletContext and WebRequest objects whenever you want to  
dynamically create a ContextAsset seems really cumbersome.

-- 
Kevin

---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org