ui:include 在 JSF 2.2 中包含错误的文件

ui:include includes wrong file in JSF 2.2

根据documentation of ui:include tag

Use this tag—which is very similar to JSP's jsp:include—to encapsulate and reuse content among multiple XHTML pages. There are three things this tag can include: plain XHTML, and XHTML pages that have either a composition tag or a component tag.

You supply a filename, through ui:include's src attribute for JSF to include. That filename is relative to the XHTML file that was rendered as a result of the last request. So, for example, if JSF loaded the view login.xhtml, and that file included pageDecorations/header.xhtml, and pageDecorations/header.xhtml included companyLogo.xhtml, then companyLogo.xhtml will not be found if it's in the pageDecorations directory, because companyLogo.xhtml has to be in the same directory as login.xhtml.


我创建了一个简单的测试:
webapp/login.xhtml

<!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:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html">

<h:body>

    <ui:include src="pageDecorations/header.xhtml" />

</h:body>
</html>

webapp/pageDecorations/header.xhtml

<ui:include 
        src="logo.xhtml"

        xmlns="http://www.w3.org/1999/xhtml"
        xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
/>

webapp/pageDecorations/logo.xhtml

<h:outputText 
      value="Logo in /pageDecorations" 
      xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
/>

webapp/logo.xhtml

<h:outputText value="Logo in /" 
      xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"

/>

当我在 WildFly 10.1 上使用 JSF 2.2 运行 这个测试(加载 login.xhtml 页面)时,我得到 Logo in /pageDecorations,而根据文档它应该是:Logo in /

怎么了 ?文档或 Mojarra 实现中是否存在错误?
还是我的理解有误?

首先,您在 webapp/ 中并执行 webapp/login.xhtml 在里面你得到 src="pageDecorations/header.xhtml" 并且为了执行你在 pageDecorations 并且从 header.xhtml 你试图找到 src="logo.xhtml" 你会得到在同一个目录中(pageDecorations)所以它会打印 "Logo in /pageDecorations"。 在这种情况下文档看起来不对。