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());

Not sure if this is how I should be doing it, but seemed to work. To get
hold of the 'servletContext', I had to inject the following property
into the calling component:

        <inject property="servletRequest"
object="service:tapestry.globals.HttpServletRequest" />

I then got a handle to the servlet context by calling:

        getServletRequest().getSession().getServletContext()

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?

-----Original Message-----
From: Joe Trewin [mailto:[EMAIL PROTECTED] 
Sent: 05 September 2005 12:05
To: Tapestry users
Subject: RE: Creating an IAsset in code from a context image

Hi,

Not sure if I'm missing something, but I can't find a class called
'ContextResourceLocation' in the Tapestry (4.0) framework ...?

Also, the interface IResourceLocation (which I'm assuming is implemented
by this?) doesn't seem to be included in the online Javadoc, although it
exists in the project.

-----Original Message-----
From: Geoff Longman [mailto:[EMAIL PROTECTED]
Sent: 31 August 2005 17:56
To: Tapestry users
Subject: Re: Creating an IAsset in code from a context image

public IAsset createAsset(ServletContext context, String path) {
  return new ContextAsset( new ContextResourceLocation(context, path),
null); }

there you go.

Geoff

On 8/31/05, Joe Trewin <[EMAIL PROTECTED]> wrote:
> Hi,
> 
> I'm tring to do a very simple thing, so I'm obviously missing 
> something here (using Tapestry 4).
> 
> I have a method which needs to return an IAsset that points to an 
> image (assume located somewhere in the web context) based on some 
> other parameters. The method is passed the component that requires the
asset.
> 
> I don't want the asset to be formally declared via a component or page

> specification file, as it's determined on the fly.
> 
> How do I do this?
> 
> I've seen hints that point towards using ContextAsset in some way, but

> can not find an obvious way to create one (the constructor takes 
> parameters that I don't know how to obtain, ie.
> "org.apache.hivemind.Resource" and "org.apache.hivemind.Location").
> Likewise with the 'ContextAssetFactory', although I'm not sure if 
> that's designed to be used outside of the core of Tapestry.
> 
> Seems simple enough, but ...
> 
> Any help gratefully recieved.
> 
> (NB. If the code needed to reference an image stored somewhere on the 
> classpath would this be a "private asset". If so, how might the code
> change?)
> 
> Joe
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 


-- 
The Spindle guy.           http://spindle.sf.net
Get help with Spindle:   
http://lists.sourceforge.net/mailman/listinfo/spindle-user
Announcement Feed:    
http://www.jroller.com/rss/glongman?catname=/Announcements
Feature Updates:            http://spindle.sf.net/updates

---------------------------------------------------------------------
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]


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

Reply via email to