mic*_*777 1 html jsf conditional-comments jsf-2 omnifaces
我想在我的JSF 2应用程序中做的是根据浏览器版本设置正确的html样式,这里是示例代码:
<!--[if lt IE 7]> <html class="lt-ie9 lt-ie8 lt-ie7" lang="en"> <![endif]-->
<!--[if IE 7]> <html class="lt-ie9 lt-ie8" lang="en"> <![endif]-->
<!--[if IE 8]> <html class="lt-ie9" lang="en"> <![endif]-->
<!--[if gt IE 8]><!--> <!--<![endif]-->
Run Code Online (Sandbox Code Playgroud)
如何在JSF 2中做到这一点?什么是最好/最简单的方法?
我在Omnifaces(o:conditionalComment
)中发现了一些有趣的东西,但它只允许有条件地加载整个css,这对我来说是无用的......
仅<o:conditionalComment>
适用于CSS文件并不是真的.这是一种误解.从技术上讲,使用纯Facelets标签/组件实现您的要求是不可能的,因为它会导致格式错误的XML语法,从而导致Facelets编译错误.
<o:conditionalComment if="lt IE 7">
<html lang="en" class="lt-ie9 lt-ie8 lt-ie7">
</o:conditionalComment>
<o:conditionalComment if="IE 7">
<html lang="en" class="lt-ie9 lt-ie8">
</o:conditionalComment>
<o:conditionalComment if="IE 8">
<html lang="en" class="lt-ie9">
</o:conditionalComment>
<o:conditionalComment if="gt IE 8">
<h:outputText value="<!-->" escape="false" />
<html lang="en" class="no-js">
<h:outputText value="<!--" escape="false" />
</o:conditionalComment>
...
</html>
Run Code Online (Sandbox Code Playgroud)
这不是 格式良好的 XML.您知道,XML结束元素应与XML start元素在同一范围内.如果每个XML 在同一个父XML元素中<html>
都有自己的XML,那么它将是有效的XML </html>
.但这反过来又不是有效的HTML.
只需<h:outputText escape="false">
在所有<html>
标签上使用.不要忘记对结束</html>
标记执行相同操作.
<o:conditionalComment if="lt IE 7">
<h:outputText value="<html lang="en" class="lt-ie9 lt-ie8 lt-ie7">" escape="false" />
</o:conditionalComment>
<o:conditionalComment if="IE 7">
<h:outputText value="<html lang="en" class="lt-ie9 lt-ie8">" escape="false" />
</o:conditionalComment>
<o:conditionalComment if="IE 8">
<h:outputText value="<html lang="en" class="lt-ie9">" escape="false" />
</o:conditionalComment>
<o:conditionalComment if="gt IE 8">
<h:outputText value="<!--><html lang="en" class="no-js"><!--" escape="false" />
</o:conditionalComment>
...
<h:outputText value="</html>" escape="false" />
Run Code Online (Sandbox Code Playgroud)
非常尴尬,但HTML5样板(这种方法起源于此)本身也很尴尬,IMO.
或者,您可以考虑<my:html>
自己创建一个自定义组件,生成所需的标记,以便您可以满足要求<my:html>...</my:html>
.