Include non-Facelet content in a Facelet template

巧了我就是萌 提交于 2019-12-12 19:07:01

问题


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="..." %>.


回答1:


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.




回答2:


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.




回答3:


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




回答4:


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.



来源:https://stackoverflow.com/questions/1489937/include-non-facelet-content-in-a-facelet-template

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!