条件注释在Facelets中呈现为HTML转义

条件注释在Facelets中呈现为HTML转义

本文介绍了<! - [if IE]>条件注释在Facelets中呈现为HTML转义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我试图使用IE条件注释来声明一个CSS资源:

I'm trying to use an IE conditional comment to declare a CSS resource:

<h:outputStylesheet name="common.css" library="css" />
<!--[if IE]>
    <link rel="stylesheet" type="text/css" href="#{resource['css:ie.css']}" />
<![endif]-->

然而,这似乎不起作用。我在生成的HTML输出中看到这一点:

However, that doesn't seem to work. I'm seeing this in my generated HTML output:

<link type="text/css" rel="stylesheet" href="/context/faces/javax.faces.resource/common.css?ln=css" />
<!--[if IE]&gt;
    &lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;/context/faces/javax.faces.resource/ie.css?ln=css&quot;/&gt;
&lt;![endif]-->

它没有条件注释就可以正常工作。我没有使用上下文参数。这是如何引起的,我该如何解决呢?

It works fine without the conditional comment. I'm not using the context parameter javax.faces.FACELETS_SKIP_COMMENTS. How is this caused and how can I solve it?

推荐答案

内容。最好的办法是将它放在< h:outputText escape =false> 中,如下所示:

This indeed won't work as Facelets implicitly HTML-escapes the comment's contents. Your best bet is to put it in a <h:outputText escape="false"> as follows:

这是一个丑陋的线。 具有:

<h:outputText value="&lt;!--[if IE]&gt;&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;/#{resource['css:ie.css']}&quot; /&gt;&lt;![endif]--&gt;" escape="false" />

This is however a line of ugliness. The OmniFaces JSF utility library has a <o:conditionalComment> for exactly this purpose:






无关具体问题,你不是真正使用属性的正确方法。它应该标识一个共同的主题,而不是放置文件的子文件夹,只是把该子文件夹放在 name 属性中。另请参见


Unrelated to the concrete problem, you are not really using the library attribute the right way. It should identify a common "theme", not the subfolder where the files are placed in, just put that subfolder in the name attribute instead. See also What is the JSF resource library for and how should it be used?

<h:outputStylesheet name="css/common.css" />
<o:conditionalComment if="IE">
    <link rel="stylesheet" type="text/css" href="#{resource['css/ie.css']}" />
</o:conditionalComment>

这篇关于&lt;! - [if IE]&gt;条件注释在Facelets中呈现为HTML转义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 01:31