Reputation: 90467
Here is my setup:
faces-config.xml
/javax.faces.resource/*
is already mapped to facesServlet in web.xml
The style.css
is :
body {
background: url("image/background.png");
}
body .test{
background-image: url("#{resource['css:image/background.png']}");
}
Then I request http://localhost:8080/app/javax.faces.resource/style.css?ln=css
and the respond is :
body {
background: url("image/background.png");
}
body .test{
background-image: url("/app/javax.faces.resource/image/background.png?ln=css");
}
I expect that all the relative URLs in CSS will be converted to the JSF 's valid URL like what #{resource}
does such that I do not have to use #{resource}
to refer to the relative URLs in CSS anymore , but the background
's relative URL of the body
selector still remains unchanged .
Update to BalusC 's reply:
If resource library is used , adding ?ln=libraryname
to all CSS images will work!
But if resource library is not used , <h:outputStylesheet name="css/style.css" />
generates <link rel="stylesheet" media="screen" type="text/css" href="/app/javax.faces.resource/css/style.css.xhtml">
If I understand correctly from this , using UnmappedResourceHandler and mapping
/javax.faces.resource/*
to the facesServlet
in web.xml
should cause JSF generates the link of the style.css
without xhtml
extension.
Upvotes: 1
Views: 1022
Reputation: 1108802
You're using css
as a resource library as in:
<h:outputStylesheet library="css" name="style.css" />
This is not right. It's just a folder:
<h:outputStylesheet name="css/style.css" />
This will produce /javax.faces.resource/css/style.css
URL instead of /javax.faces.resource/style.css?ln=css
. You've otherwise to specify it in the image URL as well:
background: url("image/background.png?ln=css");
I will update the javadoc to clarify that more.
Upvotes: 1