Error adding CSS / JS to the head of a page in JSF

4

I'm trying to include a CSS in a JSF view. However, I am not succeeding.

Below is an excerpt from the view:

<h:head>
    <h:outputStylesheet library="css" name="bootstrap.css"  />
</h:head>

The version of JSF is 2.2.12.

How much folder structure do we have:

AndtheresultingHTMLis:

What should be happening?

    
asked by anonymous 27.07.2015 / 21:54

2 answers

4

You can add CSS or JavaScript like this:

<link rel="stylesheet" href="#{facesContext.externalContext.requestContextPath}/resources/css/bootstrap.css" />

More about FacesContext

Faces Context   used when we want to access information related to processing each JSF request and rendering the corresponding response.

Note 1: The question is for JSF 2.2 , but applies to other versions as well.

Note 2: I did not realize that the AP was using Maven, if the folders are in the right place (webapp folder), it is also possible to do this: p>

<h:outputStylesheet library="css" name="index.css" />
    
27.07.2015 / 22:02
3

RES_NOT_FOUND is indicating that the resources folder was not found in webapp, this directory despite the name is not the one used by maven.

The directory referenced in the question is src / main / resources

The correct path is: src / main / webapp / resources

<h:outputStylesheet library="css" name="bootstrap.css"  />
The library attribute is a subfolder in webapp / recourses and the name attribute is the name of the file itself.

    
28.07.2015 / 17:30