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

So my template includes footer.xhtml

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

What I want to do is change the footer based on some pref users for another Footer _ ??? file. xhtml.

So, I would 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 does not exist, then let it use the contents between the tags, otherwise use the contents from the file.

I know this seems a little strange, but it will solve the huge problem of setting up my existing site without the need to make changes to it. Also, I'm not sure if the file will exist before it starts or not.

Any thoughts?

+6
source share
1 answer

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 will become just Footer.xhtml .

+4
source

Source: https://habr.com/ru/post/906506/


All Articles