有没有办法将 html 文件的内容插入到 Facelet 模板中? Facelets 标记将不起作用,因为它仅用于包含 Facelet 内容。
换句话说,我正在寻找等同于 JSP include 指令的 Facelets <%@ include file="..." %>
.
最佳答案
我可能不明白你需要什么,但是<ui:include>
不限于 facelets 内容,您可以根据 this link 插入有效的 xhtml .
考虑以下 facelets 文件 (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>
以及以下 HTML 文件 (testinclude.html):
<h2>Text from included page</h2>
它正确地包含页面中的 HTML 内容。这也适用于使用 <ui:include>
时在 facelets 模板中。
关于jsf - 在 Facelet 模板中包含非 Facelet 内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1489937/