myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Volker Weber <>
Subject Re: Getting the ContextPath to set stylesheet href properly
Date Sat, 12 Nov 2005 10:31:21 GMT
Hi Wayne,

I'm not shure about the 'best' way to solve this, but one of the easyest
is to provide a bean method for getting the contectPath.

public static String getContextPath() {

Put this in a ManagedBean, then you can access it like this:

<link rel="stylesheet"

Note the '${...}', the '#{...}' syntax can only used inside jsf tag



Wayne Fay wrote:
> Hi guys,
> Having some real problems with paths in my Faces app for some reason!
> I am using Oracle App Server 10g 10.1.2 with MyFaces 1.1.0, JSP 1.2 &
> Web-app 2.3. Wish I could use Web-app 2.4 but 10.1.2 does not support
> it, and it requires DTDs in config xml files etc. Lots of fun.
> File structure:
> \index.jsp
> \style\css\project.css
> \uploadfile.jsp
> \results\uploadfile.jsp
> \results\pageheader.jsp
> \results\externaldata.jsp
> I am including pageheader.jsp in each page in my project like so:
> <?xml version="1.0" encoding="utf-8" standalone="yes" ?>
> <jsp:root xmlns:jsp="" version="1.2"
>           xmlns:f=""
>           xmlns:h=""
>           xmlns:t="">
> < contentType="text/html;charset=utf-8"/>
> <f:view locale="#{facesContext.externalContext.request.locale}">
> <f:loadBundle basename="web.bundles.Messages" var="msg"/>
> <html>
>   <head>
>     <link rel="stylesheet" href="style/css/dcts.css" type="text/css"/>
>     <title><h:outputText value="#{msg.title}" /></title>
>       </head>
>       <body width="100%">
>         <jsp:include page="pageheader.jsp" flush="true"/> <!-- or
> /results/pageheader.jsp in files in the "root" -->
> This works some times but not always. I have also tried /style/ and
> ../style/ and it does not work every time either. It seems to depend
> on where I'm "coming from" ie coming from index.jsp, then calling a
> /results/externaldata.jsp with href="style/" works. But then if I'm in
> /results/uploadfile.jsp and call /results/externaldata.jsp, then the
> href="style/" does not work, and it requires ="../style".
> So I have decided to provide the entire path, using Context Path or
> something similar.
> I have tried:
> <link rel="stylesheet" href="<h:outputText
> value="#{facesContext.externalContext.requestContextPath}"
> />/style/css/project.css" type="text/css"/>
> does not work
> <link rel="stylesheet"
> href="${facesContext.externalContext.requestContextPath}/style/css/project.css"
> type="text/css"/>
> does not work
> <link rel="stylesheet" href="${pageContext.request.contextPath}
> /style/css/project.css" type="text/css"/>
> does not work
> Also, I'm looking for a "universal" way to refer to this
> /results/pageheader.jsp include file. In some places I have to use
> /results and in others I can just use pageheader.jsp. There must be a
> way to get the my application path (in the file system) and use it in
> the jsp:include call rather than sometimes using /results and other
> times not.
> This seems to be a pretty easy thing, but its not working for me, at
> least not consistently.
> How are the rest of you doing this?
> Thanks.
> Wayne

Don't answer to From: address!
Mail to this account are droped if not recieved via mailinglist.
To contact me direct create the mail address by
concatenating my forename to my senders domain.

View raw message