有条件地链接到CSS文件 [英] Conditional linking to an CSS file
本文介绍了有条件地链接到CSS文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的JSF2项目中,我想根据要从托管Bean获得的条件在我的Facelet页面中包含以下两个样式表.
In my JSF2 project I want to include following two style sheet to my Facelet page based on a condition which is to be obtained from a managed bean.
<link rel="stylesheet" href="css/menu_style_1.css" type="text/css" />
<link rel="stylesheet" href="css/menu_style_2.css" type="text/css" />
我该如何实现?
推荐答案
尝试
<h:outputStylesheet name="css/menu_style_1.css" target="head" rendered="#{myBean.myValue eq 'myCondition1'}"/>
和
<h:outputStylesheet name="css/menu_style_2.css" target="head" rendered="#{myBean.myValue eq 'myCondition2'}"/>
或者...您可以一行完成...
OR... you can do it in one line...
<h:outputStylesheet name="css/#{myBean.myValue == 'true' ? 'menu_style_1.css' : 'menu_style_2.css'}" target="head" />
我想如果您想坚持使用链接标签,可以尝试类似的操作
I guess if you want to stick to the link tag you can try something like that
<link rel="stylesheet" href="css/#{myBean.myValue == 'true' ? 'menu_style_1.css' : 'menu_style_2.css'}" type="text/css" />
这篇关于有条件地链接到CSS文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文