Error including CSS/JS in the head of a JSF page

Asked

Viewed 450 times

4

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

Below we have an excerpt from the view:

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

JSF version is 2.2.12.

How much folder structure we have:

Onde o css encontra-se

And the resulting HTML is:

html final

What must be happening?

  • 1

    A small observation, ss Assets should not be in the directory Resources, but in webapp. The directory change along with the @Wellingtonavelino response, worked.

  • I didn’t realize you were using Maven.

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 the processing of each JSF request and the rendering of the corresponding response.

Note 1: The question is focused on the JSF 2.2, but applies the other versions as well.

Note 2: I didn’t realize that AP was using Maven, if the folders are in the right place(webapp folder) it is also possible to do this way:

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

3

RES_NOT_FOUND is indicating that the folder Resources 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 attribute library is a subfolder in webapp/recourses and the attribute name is the name of the file itself.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.