How to conditionally include a file in my template using JSF and Facelets?

做~自己de王妃 提交于 2019-12-21 04:48:34

问题


So, my template includes a footer.xhtml

<ui:include src="/WEB-INF/testtaker/Footer.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>

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.

Any thoughts?


回答1:


You can use EL in <ui:include src>.

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

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



来源:https://stackoverflow.com/questions/8947425/how-to-conditionally-include-a-file-in-my-template-using-jsf-and-facelets

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!