My JSF Books/Videos My JSF Tutorials OmniFaces/JSF PPTs
JSF 2.3 Tutorial
JSF Caching Tutorial
JSF Navigation Tutorial
JSF Scopes Tutorial
JSF Page Author Beginner's Guide
OmniFaces 2.3 Tutorial Examples
OmniFaces 2.2 Tutorial Examples
JSF Events Tutorial
OmniFaces Callbacks Usages
JSF State Tutorial
JSF and Design Patterns
JSF 2.3 New Features (2.3-m04)
Introduction to OmniFaces
25+ Reasons to use OmniFaces in JSF
OmniFaces Validators
OmniFaces Converters
JSF Design Patterns
Mastering OmniFaces
Reusable and less-verbose JSF code

My JSF Resources ...

Java EE Guardian
Member of JCG Program
Member MVB DZone
Blog curated on ZEEF
OmniFaces is an utility library for JSF, including PrimeFaces, RichFaces, ICEfaces ...

[OmniFaces Utilities] - Find the right JSF OmniFaces 2 utilities methods/functions

Search on blog

Petition by Java EE Guardians


duminică, 3 ianuarie 2016

JSF 2.2 [usage pitfall] - Resource library meaning

As you probably know, JSF supports dedicated tags for loading resources, such as <h:outputStylesheet> for CSS resources, <h:outputScript> for JavaScript resources and <h:graphicImage> for images. These tags support an attribute named, library. The official documentation is pretty skimped about what the value of this attribute should be: The library name for this resource. Since this is all we have, there are plenty of examples like below:

<h:outputStylesheet library="css" name="style.css" />
<h:outputScript library="js" name="script.js" />
<h:graphicImage library="img" name="image.png" />

Now, the above snippet can be re-written as:

<h:outputStylesheet name="css/style.css" />
<h:outputScript name="js/script.js" />
<h:graphicImage name="img/image.png" />

Both approaches will generate almost the same HTML code. In the first approach, the library name will be rendered as a request parameter, ln=library_name, while in the second approach, the library name will be embed in the resource path as, ...javax.faces.resource/library_name/...
 So, if the generated HTML is almost the same, and in the first approach the library value simply repeats what the tag name already indicates, then how is library useful ?

We can answer to this question by checking some real world examples:

<h:outputScript library="javax.faces" name="jsf.js" />
<h:outputScript library="primefaces" name="jquery/jquery.js" />
<h:outputScript library="omnifaces" name="omnifaces.js" />
<h:outputStylesheet library="primefaces-vader" name="theme.css" />

Notice that the library value represents the common library/module/theme name where all of those resources commonly belong to. This is the correct usage that brings us several advantages:

·         Distinguish where those resources belong to and/or are coming from.
·         In custom ResourceHandlers, you can also apply more finer grained control over resources.
·         You can apply resource library versioning the right way on resources provided by your own webapp

Each of these advantages are detailed by Bauke Scholtz (aka BalusC) at What is the JSF resource library for and how should it be used?.

So, as a conclusion, if your application doesn't need a library then just omit it (e.g. some personal applications). Nevertheless, if you decide to use a library name, but you don't have a clear purpose, then a name as default or common, or your company name may be a good choice.

Niciun comentariu :

Trimiteți un comentariu


Postări populare

Follow by Email

Visitors Starting 4 September 2015

Locations of Site Visitors