In JSF 2.0, a resource is an image, document, or some other digital asset. They are placed under the resources
folder at the web context folder. In a Gradle or Maven project, a particular resource lives on the path, as shown:
src/main/webapp/resources/<RESOURCE-IDENTIFIER>
A resource may also be stored in a JAR file under the WEB-INF/lib
folder:
src/main/webapp/WEB-INF/lib/<SOME>.jar
If the resource is stored in a JAR file, it must be located in the META-INF
folder such that it can be located with the path:
META-INF/resources/<RESOURCE-IDENTIFIER>
RESOURCE-IDENTIFIER
can be further divided into separate paths. The widest case supports full internalization. The constituent parts are as follows:
<RESOURCE-IDENTIFIER> := [ <LOCALE-PREFIX> / ] [ <LIBRARY-NAME> / ] [ <LIBRARY-VERSION> / ] <RESOURCE-NAME> [ / <RESOURCE-VERSION> ]
The subterms allow the resource identifiers to be easily identified and separated out.
The optional LOCALE-PREFIX
term represents a locale such as en_gb
(British English) or de
(Germany).
The optional LIBRARY-NAME
term specifies a library name. You can define the library name and use it in the JSF custom tags, as follows:
<h:outputStylesheet library="default" name="styles/app.css" /> <h:outputStylesheet library="admin" name="styles/app.css" />
The preceding example retrieves an application style sheet that is appropriate to the library. This helps to distinguish the different parts of your digital application. The resource lookup may resolve to the following:
<WEB-CONTEXT>/resources/en/default/1_0/styles/app.css <WEB-CONTEXT>src/main/webapp/resources/en/admin/1_0/styles/app.css
These URLs map to the following source file assets in a conventional project:
src/main/webapp/resources/en/default/1_0/styles/app.css src/main/webapp/resources/en/admin/1_0/styles/app.css
Developers do not specify the library version. Instead, the JSF Resource Lookup mechanism searches for the highest version files of the respective resources. The version number of the folder name must match the regex: \d_\d
. Therefore, the version
folder name 2_0
is greater than 1_5
, which in turn, is higher than 1_0
.