根据模板客户端有条件地排除模板中的 CSS 资源文件

Conditionally exclude a CSS resource file in template depending on template client

在我的项目中,我有一个包含所有资源文件的主模板页面 main_template.xhtml

我在主模板中有一个 styles.css,其中包含我页面的 类 样式。在一个特定的页面中,我想排除 styles.css 资源文件,我该如何实现?

与所有其他 UI 组件一样,<h:outputStylesheet> 也支持 rendered 属性。您可以通过 UIViewRoot#getViewId() 获取当前视图 ID 并检查它。

所以,拼凑起来的部分看起来像:

<h:outputStylesheet ... rendered="#{view.viewId ne '/specific.xhtml'}" />

另请参阅:

  • Conditionally displaying JSF components
  • Identifying path of current JSF / XHTML page