这是我的设置:
faces-config.xml中注册/javax.faces.resource/*已经映射到web.xml中的facesServletstyle.css是:
body {
background: url("image/background.png");
}
body .test{
background-image: url("#{resource['css:image/background.png']}");
}然后我请求http://localhost:8080/app/javax.faces.resource/style.css?ln=css,响应如下:
body {
background: url("image/background.png");
}
body .test{
background-image: url("/app/javax.faces.resource/image/background.png?ln=css");
}我希望CSS中的所有相对URL都将像#{resource}一样转换为JSF的有效URL,这样我就不必再使用#{resource}来引用CSS中的相对URL了,但是background的body选择器的相对URL仍然保持不变。
更新到BalusC的回复:
?ln=libraryname添加到所有CSS映像中将有效!<h:outputStylesheet name="css/style.css" />将生成<link rel="stylesheet" media="screen" type="text/css" href="/app/javax.faces.resource/css/style.css.xhtml">。
如果我从这中正确理解,使用UnmappedResourceHandler并将/javax.faces.resource/*映射到web.xml中的facesServlet应该会导致JSF生成没有xhtml扩展的style.css链接。发布于 2013-05-31 11:08:43
您正在使用css作为资源库,如下所示:
<h:outputStylesheet library="css" name="style.css" />这是不对的。它只是一个文件夹:
<h:outputStylesheet name="css/style.css" />这将产生/javax.faces.resource/css/style.css URL而不是/javax.faces.resource/style.css?ln=css。否则,您还必须在图像URL中指定它:
background: url("image/background.png?ln=css");我将更新javadoc以澄清这一点。
另请参阅:
https://stackoverflow.com/questions/16851005
复制相似问题