Ryan has posted 7 posts at DZone. View Full User Profile

JSF 2.0 New Feature Preview Series (Part 2.3): Resources

  • submit to reddit

This is the fourth blog in the JSF 2.0 New Feature Preview Series. The previous entry covered the new resource API. This will be the last part of the Resources portion of this series and will cover leveraging the resource handling from the expression language.

A resource can be reference via the EL using the following syntax:

#{resource['<resource name>']}


#{resource['<library name>:<resource name>']}

Where and are both literals that map to a resource within the application. If using Facelets, it would be possible to output the resource URL directly without using a component:

<a href="#{resource['header.jpg']}" />;

The resource expression can also be used in h:graphicImage:

<h:graphicImage value="#{resource['corp:header.jpg']}" />;

That said, I do think the EL expression syntax is somewhat limiting (due to limitations of the EL itself). Consider theming. An application could have several themes partitioned as different resource libraries. In this situation it would be impossible to overload the library value of the expression without a custom ResourceHandler implementation.

However, it is possible to eschew the value attribute on h:graphicImage and specify a library and name attribute that accept expression to resolve the library and resource name dynamically.

Keep an eye out for the next blog entry where I'll cover the expanded event system.

Published at DZone with permission of its author, Ryan Lubke. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)


Otengi Miloskov replied on Thu, 2008/10/09 - 1:25pm

There is not annotations to include resources?, using EL like that it will get nasty the templates. Why not get rid of EL?. Instead of EL use something like expansions in Tapestry5.

I would like to have something like this:

<html><body><h:graphicImage h:id="image1" /></body></html>

Class MyPage1 {

@Resource(url="images/hello.jpg") HtmlGraphicImage image1;



 Using also Convention over Configuration.

From Wicket and T5 can learn a lot, What do you think?.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.