Due to a given requirement to show a header from an external source, we came up with the following setup (using JEE6 on Tomcat 7):
Our pages use a template regularly:
...
<ui:composition ... template="/WEB-INF/templates/template.xhtml">
...
This template additionally to laying out the structure of the page includes another XHTML file in its body:
...
<h:body>
<ui:include src="./header.xhtml" />
...
And then the included file again uses a template, but this time pointing to an external resource which returns a <div>
element containing the to be used header:
...
<ui:composition ... template="http://someserver/somefile">
...
I know that this setup is a bit strange, but the indirection was necessary in order to include the externally generated <div>
element which we had to include in our page. (In case someone can provide a smarter solution to the given problem, I'll be happy.)
This works fine so far, but it seems to be the case, that this included file gets cached by our Tomcat resulting in not showing the current header after it was changed. If Tomcat gets restarted, the new header gets shown.
Can someone give me some insight how this all works under the hood and if it's related to Facelets, Tomcat or my specific setup?
There are multiple solutions on different levels, that you might use: You could just implement a ResourceResolver and include a template from a defined URL (with a defined URL like external-resource/header.xhtml). This ResourceResolver might be configured with the external reference.
The next possibility would be to have a ServletFilter that post processes your HTML and adds the header at a defined position.
And finally you could implement a simple custom component to load the header either on server or on client side using jQuery or such.
You generally don't want to disable caching on the facelets since it will decrease performance.