You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Nathan Quirynen <na...@pensionarchitects.be> on 2014/03/27 16:19:41 UTC

Assets in component library

Hi,

I'm moving my components to a Tapestry component library. But I'm not
sure how to handle images used in those components.
Before I just put them in *src/main/webapp/images/* and then used *<img
src="${context:/images/something.png" />*

But what's the right way of handling images in a Tapestry library. I've
been trying different things without success.

1) Where do I put my images
2) How can I get the url to these images, also how if I need to get them
dynamically (use of AssetSource?)

Thanks

Re: Assets in component library

Posted by Nathan Quirynen <na...@pensionarchitects.be>.
I got it working with the following:

public String getImagePath() {
     return
assetSource.getClasspathAsset("classpath:com/company/tapestrylib/assets/components/languageselector/"
+ loopLocale.getLanguage() + ".png").toClientURL();
}

+

<img src="${imagePath}" />

+

Files located in:
src/main/resources/com/company/tapestrylib/assets/components/languageselector/


Is this the right way then?


On 28/03/14 08:55, Nathan Quirynen wrote:
> Hey Thiago,
>
> Thanks for the reply. I indeed use the maven structure and that's
> actually something I have tried, with the following error as result:
>
> Could not convert 'classpath:/assets/components/languageselector/nl.png'
> into a component parameter binding: Error parsing property expression
> 'classpath:/assets/components/languageselector/nl.png': Unable to parse
> input at character position 11.
>
> - What I did:
>
> <img src="${classpath:/assets/components/languageselector/nl.png}" />
>
> - Location of the file:
>
> src/main/resources/assets/components/languageselector/nl.png
>
>
> Am I forgetting something?
>
> -----
>
> Also if I want to get it from inside a property getter, as the images
> are rendered in a loop, how do I get the right path?
>
> - I tried the following:
>
> return
> assetSource.getClasspathAsset("assets/components/languageselector/" +
> loopLocale.getLanguage() + ".png").toClientURL();
>
> - With following error as result:
>
> Unable to create a client URL for classpath resource
> assets/components/languageselector/en.png: The resource path was not
> within an aliased path.
>
> So yea, I'm still stuck here.
>
>
> On 27/03/14 18:14, Thiago H de Paula Figueiredo wrote:
>> On Thu, 27 Mar 2014 12:19:41 -0300, Nathan Quirynen
>> <na...@pensionarchitects.be> wrote:
>>
>>> Hi,
>> Hi!
>>
>>> I'm moving my components to a Tapestry component library. But I'm not
>>> sure how to handle images used in those components.
>>> Before I just put them in *src/main/webapp/images/* and then used *<img
>>> src="${context:/images/something.png" />*
>>>
>>> But what's the right way of handling images in a Tapestry library. I've
>>> been trying different things without success.
>>>
>>> 1) Where do I put my images
>> In the classpath. If you're using the Maven source folder structure,
>> and it seems you do, /src/main/resources is the place.
>>
>>> 2) How can I get the url to these images, also how if I need to get them
>>> dynamically (use of AssetSource?)
>> ${classpath:/images/something.png}
>>


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


Re: Assets in component library

Posted by Howard Lewis Ship <hl...@gmail.com>.
Note that this will work differently, and more simply, in 5.4, where it's
just a matter of putting them into the correct sub-folder of
META-INF/assets.


On Fri, Mar 28, 2014 at 2:09 PM, Thiago H de Paula Figueiredo <
thiagohp@gmail.com> wrote:

> On Fri, 28 Mar 2014 04:55:17 -0300, Nathan Quirynen <
> nathan@pensionarchitects.be> wrote:
>
>  Hey Thiago,
>>
>
> Hi!
>
>
>  <img src="${classpath:/assets/components/languageselector/nl.png}" />
>>
>
> Please try <img src="${classpath:assets/components/languageselector/nl.png}"
> /> (notice the lack of slash before assets).
>
>
> --
> Thiago H. de Paula Figueiredo
> Tapestry, Java and Hibernate consultant and developer
> http://machina.com.br
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 
Howard M. Lewis Ship

Creator of Apache Tapestry

The source for Tapestry training, mentoring and support. Contact me to
learn how I can get you up and productive in Tapestry fast!

(971) 678-5210
http://howardlewisship.com

Re: Assets in component library

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Fri, 28 Mar 2014 04:55:17 -0300, Nathan Quirynen  
<na...@pensionarchitects.be> wrote:

> Hey Thiago,

Hi!

> <img src="${classpath:/assets/components/languageselector/nl.png}" />

Please try <img  
src="${classpath:assets/components/languageselector/nl.png}" /> (notice  
the lack of slash before assets).

-- 
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer
http://machina.com.br

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


Re: Assets in component library

Posted by Nathan Quirynen <na...@pensionarchitects.be>.
Hey Thiago,

Thanks for the reply. I indeed use the maven structure and that's
actually something I have tried, with the following error as result:

Could not convert 'classpath:/assets/components/languageselector/nl.png'
into a component parameter binding: Error parsing property expression
'classpath:/assets/components/languageselector/nl.png': Unable to parse
input at character position 11.

- What I did:

<img src="${classpath:/assets/components/languageselector/nl.png}" />

- Location of the file:

src/main/resources/assets/components/languageselector/nl.png


Am I forgetting something?

-----

Also if I want to get it from inside a property getter, as the images
are rendered in a loop, how do I get the right path?

- I tried the following:

return
assetSource.getClasspathAsset("assets/components/languageselector/" +
loopLocale.getLanguage() + ".png").toClientURL();

- With following error as result:

Unable to create a client URL for classpath resource
assets/components/languageselector/en.png: The resource path was not
within an aliased path.

So yea, I'm still stuck here.


On 27/03/14 18:14, Thiago H de Paula Figueiredo wrote:
> On Thu, 27 Mar 2014 12:19:41 -0300, Nathan Quirynen
> <na...@pensionarchitects.be> wrote:
>
>> Hi,
>
> Hi!
>
>> I'm moving my components to a Tapestry component library. But I'm not
>> sure how to handle images used in those components.
>> Before I just put them in *src/main/webapp/images/* and then used *<img
>> src="${context:/images/something.png" />*
>>
>> But what's the right way of handling images in a Tapestry library. I've
>> been trying different things without success.
>>
>> 1) Where do I put my images
>
> In the classpath. If you're using the Maven source folder structure,
> and it seems you do, /src/main/resources is the place.
>
>> 2) How can I get the url to these images, also how if I need to get them
>> dynamically (use of AssetSource?)
>
> ${classpath:/images/something.png}
>

Re: Assets in component library

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Thu, 27 Mar 2014 12:19:41 -0300, Nathan Quirynen  
<na...@pensionarchitects.be> wrote:

> Hi,

Hi!

> I'm moving my components to a Tapestry component library. But I'm not
> sure how to handle images used in those components.
> Before I just put them in *src/main/webapp/images/* and then used *<img
> src="${context:/images/something.png" />*
>
> But what's the right way of handling images in a Tapestry library. I've
> been trying different things without success.
>
> 1) Where do I put my images

In the classpath. If you're using the Maven source folder structure, and  
it seems you do, /src/main/resources is the place.

> 2) How can I get the url to these images, also how if I need to get them
> dynamically (use of AssetSource?)

${classpath:/images/something.png}

-- 
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer
http://machina.com.br

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