Reputation: 371
Is there a way to have the content of an html file inserted into a Facelet template? The Facelets tag will not work since it is only for including Facelet content.
To put it another way, I am looking for the Facelets equivalent to the JSP include directive <%@ include file="..." %>
.
Upvotes: 2
Views: 8763
Reputation: 38163
This describes a solution to this: http://arjan-tijms.omnifaces.org/2010/04/facelets-and-legacy-jsp.html
The solution includes building a simple UI component that loads the JSP or Servlet content into a string and renders that via the normal response writer.
Upvotes: 1
Reputation: 1497
Omnifaces's <o:resourceInclude>
can be used to include arbitrary content directly to the response. Which means it doesn't have to be well formed xml as with <ui:include>
. Also you can include content in <h:head>
section of your JSF page, which is tough to achieve otherwise.
http://showcase.omnifaces.org/components/resourceInclude
Upvotes: 1
Reputation: 371
The only include mechanism in Facelets is , which doesn't allow arbitrary content to be included, only well formatted XML. There is no equivalent to the JSP include directive in Facelets.
Upvotes: 1
Reputation: 15533
I may not understand what you need, but <ui:include>
is not restricted to facelets content, you can insert valid xhtml with it, according to this link.
Consider following facelets file (test.jsp):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<body>
<f:view>
<h:outputText value="Text outside include"/>
<ui:include src="testinclude.html"/>
</f:view>
</body>
</html>
And following HTML file (testinclude.html):
<h2>Text from included page</h2>
It includes correctly the HTML content in the page. This also applies when using <ui:include>
in a facelets template.
Upvotes: 4