如何使用JSF和Facelets有条件地在我的模板中包含一个文件?

Dav*_*d G 6 jsf facelets include

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

<ui:include src="/WEB-INF/testtaker/Footer.xhtml"/>
Run Code Online (Sandbox Code Playgroud)

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

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

<ui:include src="/WEB-INF/testtaker/Footer_001.xhtml">
      Content from original Footer.xhtml
</ui:include>
Run Code Online (Sandbox Code Playgroud)

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

我知道这似乎有点奇怪,但这将解决一个巨大的问题,即自定义我现有的网站,不必对所有地方进行更改.另外,我不确定该文件是否存在.

有什么想法吗?

Bal*_*usC 4

您可以在<ui:include src>.

<ui:include src="/WEB-INF/testtaker/Footer#{user.prefs.footerId}.xhtml" />
Run Code Online (Sandbox Code Playgroud)

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