OmniFaces conditionalComment未写入HTML输出 [英] OmniFaces conditionalComment not written to HTML output

查看:105
本文介绍了OmniFaces conditionalComment未写入HTML输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用OmniFaces conditionalComment加载IE 6浏览器的javascript文件.在网站上说,脚本应包含在页面中,如下所示:

I'm using OmniFaces conditionalComment to load a javascript file for IE 6 browsers. On the webiste it says the script should be included in the page as:

<script type="text/javascript" src="[JS library]"></script>
<!--[if (gte IE 6)&(lte IE 8)]>
  <script type="text/javascript" src="selectivizr.js"></script>
  <noscript><link rel="stylesheet" href="[fallback css]" /></noscript>
<![endif]-->

这是无效的xml,因此不能在JSF xhtml文件中使用.相反,我使用这个:

This is not valid xml, so can't be used in the JSF xhtml files. Instead I use this:

<h:body>
  <f:facet name="last">
    <o:conditionalComment if="if (gte IE 6)&amp;(lte IE 8)">
      <h:outputScript library="js" name="selectivizr-min.js" target="head"/>
    </o:conditionalComment>
  </f:facet>
...
</h:body>

我将脚本包含在xhtml的正文部分中,并将其放在facet name ="last"中,因此它被包含在JQuery之后(我使用PirmeFaces并认为这是最安全的方法). target ="head"确保将其写入生成的html文件的head部分.脚本的链接包含在文档的正确部分中(在PrimeFaces导入之后),但没有被条件注释包围.

I include the script in the body part of the xhtml and put it in the facet name="last", so it is included after JQuery (I use PirmeFaces and read that's the safest way to do that). target="head" ensures that it is written to the head section of the resulting html file. The link to the script is included in the correct part of the document (after the PrimeFaces imports), but it is not surrounded by the conditional comments.

以下是html的相关部分(经过重新格式化以便于阅读):

Here is the relevant part of the html (reformatted for easier reading):

<head>
  <link type="text/css" rel="stylesheet" href="/javax.faces.resource/theme.css.xhtml?ln=primefaces-aristo" />
  <link type="text/css" rel="stylesheet" href="/javax.faces.resource/primefaces.css.xhtml?ln=primefaces&amp;v=5.1" />
  <script type="text/javascript" src="/javax.faces.resource/jquery/jquery.js.xhtml?ln=primefaces&amp;v=5.1"></script>
  <script type="text/javascript" src="/javax.faces.resource/primefaces.js.xhtml?ln=primefaces&amp;v=5.1"></script>
  <script type="text/javascript" src="/javax.faces.resource/jquery/jquery-plugins.js.xhtml?ln=primefaces&amp;v=5.1"></script>
  <script type="text/javascript" src="/javax.faces.resource/omnifaces.js.xhtml?ln=omnifaces"></script>
  <link type="text/css" rel="stylesheet" href="/javax.faces.resource/styles.css.xhtml?ln=css" />
  <script type="text/javascript" src="/javax.faces.resource/selectivizr-min.js.xhtml?ln=js"></script>

最后一行缺少注释(!-[if(gte IE 6)&(lte IE 8)]> ...).

The last line is missing the comments (!--[if (gte IE 6)&(lte IE 8)]> ...).

我做错了什么?有什么建议吗?

What am I doing wrong? Any suggestions?

干杯, 多米尼克

推荐答案

此问题有两个方面:

  1. 在这种情况下,<f:facet name="last">没有任何意义.摆脱它.它会被忽略,包括其任何子级.它仅在<h:head>内部有效(甚至只有在使用PrimeFaces时才有效;后者实际上忽略了本机JSF最终订购头资源的可能性).

  1. The <f:facet name="last"> makes no sense in this context. Get rid of it. It would be ignored including any of its children. It's only valid inside <h:head> (and even then only if you're using PrimeFaces; who actually overlooked the native JSF possibility to order head resources as last).

您不能使用<h:outputScript>(也不能在<o:conditionalComment>中使用<h:outputStylesheet>,因为JSF会将其隐式自动重定位到<head>.这也在

You can't use <h:outputScript> (nor <h:outputStylesheet> inside <o:conditionalComment>, because JSF will implicitly auto-relocate it to the <head>. This is also hinted in the documentation and showcase.

只需使用普通香草<script>(或<link rel="stylesheet">).

Just use plain vanilla <script> (or <link rel="stylesheet">).

<o:conditionalComment if="(gte IE 6)&amp;(lte IE 8)">
    <script src="#{resource['js/selectivizr-min.js']}" />
</o:conditionalComment>

请注意,我通过删除重复的if修复了无效的if属性值.

Note that I fixed the invalid if attribute value by removing the duplicated if.

不相关与具体问题:library="js"表示对library属性的误解.仔细阅读

Unrelated to the concrete problem: The library="js" indicates a misunderstanding of the library attribute. Carefully read What is the JSF resource library for and how should it be used? The #{resource} resolver in above answer has already been altered to use js as regular folder instead of as library.

这篇关于OmniFaces conditionalComment未写入HTML输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆