Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

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

DZone's Guide to

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

· Web Dev Zone
Free Resource

Learn how to build modern digital experience apps with Crafter CMS. Download this eBook now. Brought to you in partnership with Crafter Software

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

OR

#{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.

Crafter is a modern CMS platform for building modern websites and content-rich digital experiences. Download this eBook now. Brought to you in partnership with Crafter Software.

Topics:

Published at DZone with permission of Ryan Lubke. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}