这是我的设置:
faces-config.xml
/javax.faces.resource/*
已映射到web.xml
style.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都会转换为JSF的有效网址,就像#{resource}
所做的那样,这样我就不必使用#{resource}
来引用相对URL了CSS已经存在,但background
选择器的body
相对网址仍保持不变。
更新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">
如果我从this正确理解,使用UnmappedResourceHandler和映射
/javax.faces.resource/*
facesServlet
web.xml
style.css
会导致JSF生成xhtml
没有{{1}}扩展名的链接。
答案 0 :(得分:1)
您正在使用css
作为资源库,如下所示:
<h:outputStylesheet library="css" name="style.css" />
这是不对的。它只是一个文件夹:
<h:outputStylesheet name="css/style.css" />
这将生成/javax.faces.resource/css/style.css
网址,而不是/javax.faces.resource/style.css?ln=css
。您也可以在图片网址中指定它:
background: url("image/background.png?ln=css");
我将更新javadoc以澄清更多内容。