You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Jean-Philippe Steinmetz <st...@ISI.EDU> on 2007/12/05 01:45:36 UTC

[T5] Obtaining a relative directory path

Hello all,
 
I am trying to create a getter that returns the relative path to the images
directory for my application. I want it to apply in template HTML files as:
 
    <img src="${imagesBase}/some_image.jpg"/>
 
I found a previous thread (
http://www.nabble.com/T5-How-to-difine-dynamic-path-for-image-t4834269.html
) on how to do this using AssetSource but this did not work for me as it
requires the java class to know the exact resource location. This isn't
beneficial when work is passed on to web designers who do not have any
programming experience, nor should have to.
 
I have also tried the following java code but I keep getting runtime errors
 
    @Inject
    @Path("context:images")
    private Asset imagesBase;
 
    public Asset getImagesBase() { return imagesBase; }
 
Any help on this would be great. Thanks.
 
Jean-Philippe Steinmetz

RE: [T5] Obtaining a relative directory path

Posted by Jean-Philippe Steinmetz <st...@ISI.EDU>.
Thanks Howard, that was very helpful =)

> -----Original Message-----
> From: Howard Lewis Ship [mailto:hlship@gmail.com] 
> Sent: Wednesday, December 05, 2007 8:08 AM
> To: Tapestry users
> Subject: Re: [T5] Obtaining a relative directory path
> 
> One more note .. if that is awkard for you ... write a 
> one-liner component to take care of this for you!
> 
> On Dec 5, 2007 8:06 AM, Howard Lewis Ship <hl...@gmail.com> wrote:
> > This should work:
> >
> > <img src="${asset:context:images/some_image.gif}"/>
> >
> >
> > The value inside a ${...} expansion is actual a binding in 
> disguise, 
> > so it can use binding prefixes such as "prop:" (the default), 
> > "message:" or "asset:".
> >
> > However, inside a template, the "current location" is on 
> the classpath 
> > (i.e., relative to your component's Java class file), so 
> you have to 
> > specify "context:" to have the path interpreted as relative 
> to the web 
> > application root.  It seems a little odd when the template file is 
> > itself in the web root, but I opted for a rule that is consistent 
> > across application pages, components and pages in libraries.
> >
> >
> >
> > On Dec 4, 2007 6:39 PM, Jean-Philippe Steinmetz 
> <st...@isi.edu> wrote:
> > > I can't use absolute URLs because I can't make any 
> assumptions about 
> > > the server environment this will run on. The server will 
> likely vary 
> > > and even the context name may change. Also, using an 
> old-fashioned 
> > > relative URL doesn't work for me either since my app is broken up 
> > > into packages. So I may have page URLs that look like 
> /MyApp/Section/Page1 or /MyApp/MainMenu.
> > >
> > > Jean-Philippe
> > >
> > >
> > > > -----Original Message-----
> > > > From: joshcanfield@gmail.com [mailto:joshcanfield@gmail.com] On 
> > > > Behalf Of Josh Canfield
> > > > Sent: Tuesday, December 04, 2007 5:17 PM
> > > > To: Tapestry users
> > > > Subject: Re: [T5] Obtaining a relative directory path
> > > >
> > > > If these are just static images in a directory in your 
> webapp then 
> > > > you don't need the functionality of an Asset for that.
> > > > How about just doing it the old fashioned way?
> > > >
> > > > <img src="/images/some_image.jpg"/>
> > > >
> > > > Most of my images are done like this... sometimes I need an 
> > > > absolute url and I prepend that.
> > > >
> > > > Josh
> > > > On Dec 4, 2007 4:45 PM, Jean-Philippe Steinmetz 
> <st...@isi.edu> 
> > > > wrote:
> > > >
> > > > > Hello all,
> > > > >
> > > > > I am trying to create a getter that returns the relative
> > > > path to the
> > > > > images directory for my application. I want it to apply in 
> > > > > template HTML files
> > > > > as:
> > > > >
> > > > >    <img src="${imagesBase}/some_image.jpg"/>
> > > > >
> > > > > I found a previous thread (
> > > > >
> > > > >
> > > > 
> http://www.nabble.com/T5-How-to-difine-dynamic-path-for-image-t483
> > > > 4269
> > > > > .html
> > > > > ) on how to do this using AssetSource but this did not work
> > > > for me as
> > > > > it requires the java class to know the exact resource
> > > > location. This
> > > > > isn't beneficial when work is passed on to web 
> designers who do 
> > > > > not have any programming experience, nor should have to.
> > > > >
> > > > > I have also tried the following java code but I keep
> > > > getting runtime
> > > > > errors
> > > > >
> > > > >    @Inject
> > > > >    @Path("context:images")
> > > > >    private Asset imagesBase;
> > > > >
> > > > >    public Asset getImagesBase() { return imagesBase; }
> > > > >
> > > > > Any help on this would be great. Thanks.
> > > > >
> > > > > Jean-Philippe Steinmetz
> > > > >
> > > >
> > > >
> > > >
> > > > --
> > > > --
> > > > TheDailyTube.com. Sign up and get the best new videos on the 
> > > > internet delivered fresh to your inbox.
> > > >
> > >
> > >
> > >
> > > 
> --------------------------------------------------------------------
> > > - To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> > > For additional commands, e-mail: users-help@tapestry.apache.org
> > >
> > >
> >
> >
> >
> > --
> > Howard M. Lewis Ship
> > TWD Consulting, Inc.
> >
> > Creator Apache Tapestry and Apache HiveMind
> >
> 
> 
> 
> --
> Howard M. Lewis Ship
> TWD Consulting, Inc.
> 
> Creator Apache Tapestry and Apache HiveMind
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 



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


Re: [T5] Obtaining a relative directory path

Posted by Howard Lewis Ship <hl...@gmail.com>.
One more note .. if that is awkard for you ... write a one-liner
component to take care of this for you!

On Dec 5, 2007 8:06 AM, Howard Lewis Ship <hl...@gmail.com> wrote:
> This should work:
>
> <img src="${asset:context:images/some_image.gif}"/>
>
>
> The value inside a ${...} expansion is actual a binding in disguise,
> so it can use binding prefixes such as "prop:" (the default),
> "message:" or "asset:".
>
> However, inside a template, the "current location" is on the classpath
> (i.e., relative to your component's Java class file), so you have to
> specify "context:" to have the path interpreted as relative to the web
> application root.  It seems a little odd when the template file is
> itself in the web root, but I opted for a rule that is consistent
> across application pages, components and pages in libraries.
>
>
>
> On Dec 4, 2007 6:39 PM, Jean-Philippe Steinmetz <st...@isi.edu> wrote:
> > I can't use absolute URLs because I can't make any assumptions about the
> > server environment this will run on. The server will likely vary and even
> > the context name may change. Also, using an old-fashioned relative URL
> > doesn't work for me either since my app is broken up into packages. So I may
> > have page URLs that look like /MyApp/Section/Page1 or /MyApp/MainMenu.
> >
> > Jean-Philippe
> >
> >
> > > -----Original Message-----
> > > From: joshcanfield@gmail.com [mailto:joshcanfield@gmail.com]
> > > On Behalf Of Josh Canfield
> > > Sent: Tuesday, December 04, 2007 5:17 PM
> > > To: Tapestry users
> > > Subject: Re: [T5] Obtaining a relative directory path
> > >
> > > If these are just static images in a directory in your webapp
> > > then you don't need the functionality of an Asset for that.
> > > How about just doing it the old fashioned way?
> > >
> > > <img src="/images/some_image.jpg"/>
> > >
> > > Most of my images are done like this... sometimes I need an
> > > absolute url and I prepend that.
> > >
> > > Josh
> > > On Dec 4, 2007 4:45 PM, Jean-Philippe Steinmetz
> > > <st...@isi.edu> wrote:
> > >
> > > > Hello all,
> > > >
> > > > I am trying to create a getter that returns the relative
> > > path to the
> > > > images directory for my application. I want it to apply in template
> > > > HTML files
> > > > as:
> > > >
> > > >    <img src="${imagesBase}/some_image.jpg"/>
> > > >
> > > > I found a previous thread (
> > > >
> > > >
> > > http://www.nabble.com/T5-How-to-difine-dynamic-path-for-image-t4834269
> > > > .html
> > > > ) on how to do this using AssetSource but this did not work
> > > for me as
> > > > it requires the java class to know the exact resource
> > > location. This
> > > > isn't beneficial when work is passed on to web designers who do not
> > > > have any programming experience, nor should have to.
> > > >
> > > > I have also tried the following java code but I keep
> > > getting runtime
> > > > errors
> > > >
> > > >    @Inject
> > > >    @Path("context:images")
> > > >    private Asset imagesBase;
> > > >
> > > >    public Asset getImagesBase() { return imagesBase; }
> > > >
> > > > Any help on this would be great. Thanks.
> > > >
> > > > Jean-Philippe Steinmetz
> > > >
> > >
> > >
> > >
> > > --
> > > --
> > > TheDailyTube.com. Sign up and get the best new videos on the
> > > internet delivered fresh to your inbox.
> > >
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> > For additional commands, e-mail: users-help@tapestry.apache.org
> >
> >
>
>
>
> --
> Howard M. Lewis Ship
> TWD Consulting, Inc.
>
> Creator Apache Tapestry and Apache HiveMind
>



-- 
Howard M. Lewis Ship
TWD Consulting, Inc.

Creator Apache Tapestry and Apache HiveMind

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


Re: [T5] Obtaining a relative directory path

Posted by Howard Lewis Ship <hl...@gmail.com>.
This should work:

<img src="${asset:context:images/some_image.gif}"/>


The value inside a ${...} expansion is actual a binding in disguise,
so it can use binding prefixes such as "prop:" (the default),
"message:" or "asset:".

However, inside a template, the "current location" is on the classpath
(i.e., relative to your component's Java class file), so you have to
specify "context:" to have the path interpreted as relative to the web
application root.  It seems a little odd when the template file is
itself in the web root, but I opted for a rule that is consistent
across application pages, components and pages in libraries.


On Dec 4, 2007 6:39 PM, Jean-Philippe Steinmetz <st...@isi.edu> wrote:
> I can't use absolute URLs because I can't make any assumptions about the
> server environment this will run on. The server will likely vary and even
> the context name may change. Also, using an old-fashioned relative URL
> doesn't work for me either since my app is broken up into packages. So I may
> have page URLs that look like /MyApp/Section/Page1 or /MyApp/MainMenu.
>
> Jean-Philippe
>
>
> > -----Original Message-----
> > From: joshcanfield@gmail.com [mailto:joshcanfield@gmail.com]
> > On Behalf Of Josh Canfield
> > Sent: Tuesday, December 04, 2007 5:17 PM
> > To: Tapestry users
> > Subject: Re: [T5] Obtaining a relative directory path
> >
> > If these are just static images in a directory in your webapp
> > then you don't need the functionality of an Asset for that.
> > How about just doing it the old fashioned way?
> >
> > <img src="/images/some_image.jpg"/>
> >
> > Most of my images are done like this... sometimes I need an
> > absolute url and I prepend that.
> >
> > Josh
> > On Dec 4, 2007 4:45 PM, Jean-Philippe Steinmetz
> > <st...@isi.edu> wrote:
> >
> > > Hello all,
> > >
> > > I am trying to create a getter that returns the relative
> > path to the
> > > images directory for my application. I want it to apply in template
> > > HTML files
> > > as:
> > >
> > >    <img src="${imagesBase}/some_image.jpg"/>
> > >
> > > I found a previous thread (
> > >
> > >
> > http://www.nabble.com/T5-How-to-difine-dynamic-path-for-image-t4834269
> > > .html
> > > ) on how to do this using AssetSource but this did not work
> > for me as
> > > it requires the java class to know the exact resource
> > location. This
> > > isn't beneficial when work is passed on to web designers who do not
> > > have any programming experience, nor should have to.
> > >
> > > I have also tried the following java code but I keep
> > getting runtime
> > > errors
> > >
> > >    @Inject
> > >    @Path("context:images")
> > >    private Asset imagesBase;
> > >
> > >    public Asset getImagesBase() { return imagesBase; }
> > >
> > > Any help on this would be great. Thanks.
> > >
> > > Jean-Philippe Steinmetz
> > >
> >
> >
> >
> > --
> > --
> > TheDailyTube.com. Sign up and get the best new videos on the
> > internet delivered fresh to your inbox.
> >
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>



-- 
Howard M. Lewis Ship
TWD Consulting, Inc.

Creator Apache Tapestry and Apache HiveMind

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


RE: [T5] Obtaining a relative directory path

Posted by Jean-Philippe Steinmetz <st...@ISI.EDU>.
I can't use absolute URLs because I can't make any assumptions about the
server environment this will run on. The server will likely vary and even
the context name may change. Also, using an old-fashioned relative URL
doesn't work for me either since my app is broken up into packages. So I may
have page URLs that look like /MyApp/Section/Page1 or /MyApp/MainMenu.

Jean-Philippe

> -----Original Message-----
> From: joshcanfield@gmail.com [mailto:joshcanfield@gmail.com] 
> On Behalf Of Josh Canfield
> Sent: Tuesday, December 04, 2007 5:17 PM
> To: Tapestry users
> Subject: Re: [T5] Obtaining a relative directory path
> 
> If these are just static images in a directory in your webapp 
> then you don't need the functionality of an Asset for that. 
> How about just doing it the old fashioned way?
> 
> <img src="/images/some_image.jpg"/>
> 
> Most of my images are done like this... sometimes I need an 
> absolute url and I prepend that.
> 
> Josh
> On Dec 4, 2007 4:45 PM, Jean-Philippe Steinmetz 
> <st...@isi.edu> wrote:
> 
> > Hello all,
> >
> > I am trying to create a getter that returns the relative 
> path to the 
> > images directory for my application. I want it to apply in template 
> > HTML files
> > as:
> >
> >    <img src="${imagesBase}/some_image.jpg"/>
> >
> > I found a previous thread (
> >
> > 
> http://www.nabble.com/T5-How-to-difine-dynamic-path-for-image-t4834269
> > .html
> > ) on how to do this using AssetSource but this did not work 
> for me as 
> > it requires the java class to know the exact resource 
> location. This 
> > isn't beneficial when work is passed on to web designers who do not 
> > have any programming experience, nor should have to.
> >
> > I have also tried the following java code but I keep 
> getting runtime 
> > errors
> >
> >    @Inject
> >    @Path("context:images")
> >    private Asset imagesBase;
> >
> >    public Asset getImagesBase() { return imagesBase; }
> >
> > Any help on this would be great. Thanks.
> >
> > Jean-Philippe Steinmetz
> >
> 
> 
> 
> --
> --
> TheDailyTube.com. Sign up and get the best new videos on the 
> internet delivered fresh to your inbox.
> 



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


Re: [T5] Obtaining a relative directory path

Posted by Josh Canfield <jo...@thedailytube.com>.
If these are just static images in a directory in your webapp then you don't
need the functionality of an Asset for that. How about just doing it the old
fashioned way?

<img src="/images/some_image.jpg"/>

Most of my images are done like this... sometimes I need an absolute url and
I prepend that.

Josh
On Dec 4, 2007 4:45 PM, Jean-Philippe Steinmetz <st...@isi.edu> wrote:

> Hello all,
>
> I am trying to create a getter that returns the relative path to the
> images
> directory for my application. I want it to apply in template HTML files
> as:
>
>    <img src="${imagesBase}/some_image.jpg"/>
>
> I found a previous thread (
>
> http://www.nabble.com/T5-How-to-difine-dynamic-path-for-image-t4834269.html
> ) on how to do this using AssetSource but this did not work for me as it
> requires the java class to know the exact resource location. This isn't
> beneficial when work is passed on to web designers who do not have any
> programming experience, nor should have to.
>
> I have also tried the following java code but I keep getting runtime
> errors
>
>    @Inject
>    @Path("context:images")
>    private Asset imagesBase;
>
>    public Asset getImagesBase() { return imagesBase; }
>
> Any help on this would be great. Thanks.
>
> Jean-Philippe Steinmetz
>



-- 
--
TheDailyTube.com. Sign up and get the best new videos on the internet
delivered fresh to your inbox.