UnmappedResourceHandler无法将CSS中的URL转换为JSF的有效URL

时间:2013-05-31 06:28:05

标签: jsf jsf-2 omnifaces unmappedresourcehandler

这是我的设置:

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的回复:

  1. 如果使用资源库,将?ln=libraryname添加到所有CSS图像将会有效!

  2. 但如果未使用资源库,<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}}扩展名的链接。

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以澄清更多内容。

另见: