如何使用JSF和Facelets有条件地在我的模板中包含一个文件? [英] How to conditionally include a file in my template using JSF and Facelets?

查看:105
本文介绍了如何使用JSF和Facelets有条件地在我的模板中包含一个文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我的模板包含一个footer.xhtml

So, my template includes a footer.xhtml

<ui:include src="/WEB-INF/testtaker/Footer.xhtml"/>

我想要做的是根据一些用户pref更改页脚到不同的页脚_ ??? xhtml文件。

What I want to do is change the footer based on some users pref to different Footer_???.xhtml file.

所以,我想做这样的事情:

So, I'd like to do something like this:

<ui:include src="/WEB-INF/testtaker/Footer_001.xhtml">
      Content from original Footer.xhtml
</ui:include>

如果Footer_001.xhtml不存在,则让它使用标签之间的内容,否则使用文件中的内容。

and if Footer_001.xhtml doesn't exist, then let it use the content between the tags, otherwise use the content from the file.

我知道这看起来有点奇怪,但这将解决自定义现有网站的一个巨大问题,无需对包含进行更改到处都是。另外,我不确定该文件是否会存在。

I know this seems a little odd, but this will solve a huge problem of customizing my existing site with out having to make changes to includes all over the place. Plus I'm not sure the file will exist before hand or not.

有什么想法吗?

推荐答案

您可以在< ui:include src> 中使用EL。

<ui:include src="/WEB-INF/testtaker/Footer#{user.prefs.footerId}.xhtml" />

如果#{user.prefs.footerId} 返回 null 或空字符串,它将变为 Footer.xhtml

If #{user.prefs.footerId} returns null or an empty string, it'll become just Footer.xhtml.

这篇关于如何使用JSF和Facelets有条件地在我的模板中包含一个文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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