JSF Web Resources
JSF web resources are the resources which are required for proper rendering in the web application. It includes images, script files, and any user-created component libraries.
JSF provides a standard way to store your web resources. You can use any one of the following to store your resources.
The JavaServer Faces runtime will look for the resources in the preceding listed locations, in that order.
JSF Web Resources Example: Accessing Image File
JSF provides <h:graphicImage /> tag to access Image in web application. In the following example, first we have created a resources and a sub folder named images. After creating the folders our application structure looks like the below.
Now, you can write your code like below. The <h:graphicImage> tag specifies that the image named hello.gif is in the directory web pages/resources/images.
In this code, we are accessing image by using two ways. One is by using resource array in expression language. Second, by specifying library attribute.
both image tag produce the same output.
JSF Web Resources Example: Accessing CSS File
The <h:outputStylesheet> tag is used to access CSS resource in the web application. You must create a subdirectory inside the resources folder as given below.
In the following example, we are accessing test.css file in our web page.