Search code examples
jsf-2facelets

Include static HTML (invalid XHTML) file to JSF Facelets


I have the following problem, We have web content manager (WCM) running at remote host, which is responsible for generating header and footer HTML files. i.e. header.html, footer.html. The HTML files are not properly formatted syntax wise, WCM generated files have

  1. Space character ( ) 🡢 it is not allowed in XHTML.
  2. Non Closing break line (<br>) tags 🡢 it is invalid in XHTML.

So the WCM generated HTML pages might not be valid XHTML pages.

We are implementing some of our applications in JSF, where we need to include the WCM generated header and footer files. Can we include the non-formatted HTML files into our XHTML files?

commonTemplate.xhtml

<html>
<head>
..........;
</head>
<body>
<ui:include src="remote_host/header.html" />

<ui:insert name="commonBodyContent" />

<ui:include src="remote_host/footer.html" />
</body>
</html>

Solution

  • I guess it is related to this question: Include non-Facelet content in a Facelet template

    I do not recommend to mix XHTML with HTML, but most probably the browsers will not have any issues with the mentioned characters, hence you might try to directly render the file contenty, e.g. by

    <h:outputText value="#{yourBean.headerCode}" escape="false" />
    

    Whereas YourBean.getHeaderCode() would readout the header file's content and return it as String. YourBean should be ApplicationScoped.

    Faster and better would be to get the WCM generating valid XHTML.