6

How can I include CSS stylesheets relative to context path in JSF 1.1?

<link href="{CONTEXT}/css/style.css" rel="stylesheet" type="text/css"/>

Like we use in JSF2.

<link href="#{resource['css:styles.css']}" rel="stylesheet" type="text/css"/>

2 Answers 2

11

Depends on the view technology being used:

If JSP(X), use ${pageContext.request.contextPath}:

<link href="${pageContext.request.contextPath}/css/style.css" rel="stylesheet" type="text/css"/>

If Facelets 1.x, use #{facesContext.externalContext.requestContextPath}:

<link href="#{facesContext.externalContext.requestContextPath}/css/style.css" rel="stylesheet" type="text/css"/>

If Facelets 2.x, use #{request.contextPath}:

<link href="#{request.contextPath}/css/style.css" rel="stylesheet" type="text/css"/>

Note that there's no support for #{resource} nor <h:outputStylesheet> in JSF 1.x.

Sign up to request clarification or add additional context in comments.

4 Comments

#{request.contextPath} returns nothing.
Are you using Facelets or JSPX? When you said XHTML I assumed it to be Facelets. In JSP(X) you should use ${pageContext.request.contextPath} instead. I edited the answer.
Tnx for your response. I am using facelet. I have resolved the issue by using #{facesContext.externalContext.requestContextPath}.
Hi @BalusC, I'm using Facelets 2.3. #{facesContext.externalContext.requestContextPath} works. But #{request.contextPath} does not; it returns empty string. Do you know why?
0

I'm using JSF 2.2 with mojarra 2.2.

#{facesContext.externalContext.requestContextPath}

solves the problem for me; I was using a facelet (.xhtml).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.