Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6617871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:45:22+00:00 2026-05-25T20:45:22+00:00

In my JSF 2.0 Facelets application I have one glorious template that I want

  • 0

In my JSF 2.0 Facelets application I have one glorious template that I want all the pages to use. It is in the root directory of the web-app disguised with the name template.xhtml. So it is referenced as you would expect:

<ui:composition template="./template.xhtml">

However I do navigate now and then to client files in sub-directories. It is useful to organize them this way because of different privilege levels. The facelets in those subdirectories would have a reference to the same template like this:

<ui:composition template="../template.xhtml">

So far so good. However in the header of the template I pull in the css like this:

<link href="./resources/css/default.css" rel="stylesheet" type="text/css" />
<link href="./resources/css/tableLayout.css" rel="stylesheet" type="text/css" />
<link href="../resources/css/default.css" rel="stylesheet" type="text/css" />
<link href="../resources/css/tableLayout.css" rel="stylesheet" type="text/css" />

The reason for the redundant references is that I haven’t found any other way to get the template to work from the context of the root directory or the sub-directory. A pathname that starts with a / doesn’t work unless you put the application name in it like this

/TheApp-Ver1_0/resources/css/default.css

The problem with this is that the absolute pathname starts with a variable, not a constant. The variable is dependent on how the app is deployed in the container. Is there any clean way of resolving this?

I did some searches to find this question. Honest. However I suspect this is another one of those where BalusC swoops in an provides a link to the blindingly obvious solution extensively discussed somewhere I missed.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T20:45:23+00:00Added an answer on May 25, 2026 at 8:45 pm

    The template path in <ui:composition> is relative to the webapp’s own folder structure, not to the domain root (because it does not represent an URL!). So if you start it with /, it’s just resolved relative to the context root.

    <ui:composition template="/WEB-INF/inc/template.xhtml">
    

    (putting in /WEB-INF has the advantage that the enduser cannot open it directly by guessing the URL)

    The name path of <h:outputStylesheet>, <h:outputScript> and <h:graphicImage> is always relative to /resources root folder, regardless of if you start it with / or not.

    <h:outputStylesheet name="css/default.css" />
    <h:outputScript name="js/default.js" />
    <h:graphicImage name="img/logo.png" />
    

    If you want to use plain HTML instead of JSF components to include CSS/JS/images for some reason, then best is to prepend the path with #{request.contextPath} yourself, so that you can make it a domain-relative URL, so that you don’t need to fiddle with context-relative URLs. See also: How get the base URL?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a dynamic web application in Java EE with JSF, Facelets, Richfaces. My
I have a Facelets(JSF 1.2 (myfaces)) web app and I want to customize my
I have a JSF 1.2 application (Sun RI, Facelets, Richfaces) that was used only
I have developed a java web application using JSF 2.0(Facelets) on GlassFish 3.1.1 with
I'm building a JSF+Facelets web app, one piece of which is a method that
For a web application I make use of JSF 1.2 and Facelets. The problem
I'm using JSF 1.2 with Richfaces and Facelets. I have an application with many
I`m developing an application using Spring WebFlow 2, Facelets and JSF. One of my
I am currently working on a JAVA web application using JSF, Facelets, JSTL and
I have jsf application in which I have to use a facelet custom component

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.