无法让 Omnifaces 资源处理程序工作:无法找到资源

Can't get Omnifaces resource handlers to work: Unable to find resource

org.omnifaces.resourcehandler.CDNResourceHandlerorg.omnifaces.resourcehandler.UnmappedResourceHandler 我都试过了。一定是配置有误,但我找不到问题所在:

faces-config-xml:

<faces-config ...>
  <application>
  ....
    <resource-handler>org.omnifaces.resourcehandler.CDNResourceHandler</resource-handler>
    <resource-handler>org.omnifaces.resourcehandler.UnmappedResourceHandler</resource-handler>
  ...

web.xml:

<web-app ...>

...

  <context-param>
    <param-name>org.omnifaces.CDN_RESOURCE_HANDLER_URLS</param-name>
    <param-value>
      ionicons:ionicons.min.css=http://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css
    </param-value>
  </context-param>

...

然后在我的jsf页面上:

<h:outputStylesheet name="ionicons.min.css" library="ionicons" />

我没有收到来自 "Resource not found" 错误的运行时警告或错误:

Unable to find resource ionicons, ionicons.min.css

我正在使用 mojarra 2.2.5 和 tomcat 6.0.41。我已经尝试过 omnifaces 1.7 和 1.10(我的项目也使用 primefaces,但我不知道这是否相关)。关于如何找出问题的任何想法?

UnmappedResourceHandler不支持资源库。 javadoc and showcase.

中提到了它

And the following CSS file reference (note: the library is not supported by the UnmappedResourceHandler! this is a technical limitation, just exclusively use name):

<h:outputStylesheet name="css/style.css" />

技术限制是无法从 CSS 文件中相对引用资源。使用库时,在您的特定情况下,路径 /ionicons 将移动到查询参数 ?ln=ionicons,然后 CSS 文件将在错误的相对文件夹 [=19] 中查找相关图像引用=] 而不是 /resources/ionicons.

只需将 library 移动到 name:

<h:outputStylesheet name="ionicons/ionicons.min.css" />
<param-value>
  ionicons/ionicons.min.css=http://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css
</param-value>

更新:毕竟,看来你其实并不需要CDNResourceHandler。它的主要设计目的是能够将 auto-included JSF 资源(例如标准 JSF 的 javax.faces:jsf.js 和 PrimeFaces 的 primefaces:jquery/jquery.js 移动到 CDN 主机。标准 JSF 不为此提供任何可能性。

如果您确实需要引用外部 CSS 或 JS 资源,只需使用普通 <link><script> 而不是 <h:outputStylesheet><h:outputScript>

<link rel="stylesheet" href="http://cdn.example.com/style.css" />
<script src="http://cdn.example.com/script.js"></script>

如果您打算对其进行模板化以便可以 use target="head" of the usual JSF resource components,则声明一个单独的 <ui:insert>。例如。在主模板中

<h:head>
    ...
    <ui:insert name="head-resources" />
</h:head>

并在模板客户端中

<ui:define name="head-resources">
    ...
</ui:define>