The absolute path name in my template for getting resources

In my JSF 2.0 Facelets app, I have one nice template that I want all pages to use. It is located in the root directory of the web application disguised as template.xhtml. Therefore, it refers as you expected:

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

However, I view client files in subdirectories. It is useful to organize them this way because of different privilege levels. Persons in these subdirectories will refer to the same template:

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

So far so good. However, in the template header, I draw in css as follows:

<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 redundant links is that I did not find another way to make the template work from the context of the root directory or subdirectory. A path name starting with / does not work unless you enter the application name into it, as shown

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

The problem is that the absolute path starts with a variable, not a constant. The variable depends on how the application is deployed in the container. Is there any clean way to resolve this?

I did a few searches to find this question. Fair. However, I suspect this is another one where BalusC swoops in a provides a link to a dazzlingly obvious solution, widely discussed somewhere that I missed.

+5
source share
1 answer

template <ui:composition> webapp, ( URL!). , /, .

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

( /WEB-INF , , URL-)

name <h:outputStylesheet>, <h:outputScript> <h:graphicImage> /resources, , / .

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

HTML JSF- CSS/JS/ - , #{request.contextPath} , URL-, - URL-. . : URL?

+14

All Articles