Here is my setup:
- Web app 's folder structure and file names are exactly the same as the UnmappedResourceHandler 's javadoc
- UnmappedResourceHandler is already registered in
faces-config.xml
/javax.faces.resource/*
is already mapped to facesServlet inweb.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 thefacesServlet
inweb.xml
should cause JSF generates the link of thestyle.css
withoutxhtml
extension.