Suppose this example:
The template page (template1.xhtml) includes the content under "container" section but note f:metadata is outside that part so it is not included.
The compilation suppose 2 steps:
- Build a view metadata facelet, which only has what's inside <f:metadata> section, no matter where is it.
- Build a normal facelet, which builds the component tree itself.
In this case, when the normal facelet is applied, the section under f:metadata is removed by facelets refresh algorithm, because it is not included in that facelet. It is an effect that is difficult to see, but it appear when you have a preRenderView listener or in the tests using JSF 2.2 f:viewAction.
The spec javadoc suggest do this instead:
<!-- ..... -->
And add in the template on the top level a simple <ui:insert name="metadata/> to include the section when facelets process the page.
Other alternative is use this syntax:
It also works but the point is f:metadata is never inside a <c:if> section or any other that changes the tree structure dynamically, because the compilation suppose only it should be located at the top page level and not in a template client.
So, the first syntax should be valid, and its more, even put f:metadata outside ui:composition should work, because the syntax is smaller.
The proposed fix is exclude f:metadata facet from mark/delete algorithm, just adding some lines in DefaultFacelet.