In my third post of the series on JSF 2.2 features I will present a small extension of the JSF resource handling mechanism. JSF 2.2 allows to configure the directory used for resource lookup.
By default, the resource handling mechanism introduced in JSF 2.0 looks up resource in the following locations:
- In /resources under the web application root folder.
- In /META-INF/resources in JAR files.
The disadvantage of
/resources is that everything in that folder is accessible from outside by default. This is not always desirable, especially for composite components. Therefore, JSF 2.2 introduces the context parameter
javax.faces.WEBAPP_RESOURCES_DIRECTORY to specify the directory used for resource lookup in the file system of the web application (point 1 in the list above). In the listing below, the path is moved to
/WEB-INF/resources for instance. Resources inside
/WEB-INF can be accessed by JSF but never from the “outside world”.
<context-param> <param-name> javax.faces.WEBAPP_RESOURCES_DIRECTORY </param-name> <param-value>/WEB-INF/resources</param-value> </context-param>
For demonstration, I took the collapsible panel component from the ajaxified collapsible panel post and moved the resource directory to
The following figure shows the updated content and folder structure of the library containing the component and all required resources:
The source code for the JSF 2.2 series examples can be found in the JSFlive Github repository jsf22-examples (module
Further official details about JSF 2.2 can be found in the JSR 344: JavaServer Faces 2.2.