JSF模板:呈现的页面缺少DOCTYPE

时间:2011-09-21 19:03:29

标签: jsf facelets

TL; DR:我无法在我的JSF页面上显示DOCTYPE标题。

我刚刚继承了一个在IE下有一些显示问题的JSF 1.2项目。我是JSF的新手,但我认为问题源于渲染页面(来自“视图源”)不包含正确的DOCTYPE

页面由多个部分组成,使用多个<ui:composition>层组合在一起。典型页面如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                template="../layout/template.xhtml">

    <ui:define name="body">
      <!-- html content goes here... -->
    </ui:define>
</ui:composition>

然后../layout/template.xhtml有:

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                template="./headertemplate.xhtml">

    <ui:define name="menuSelection">
        <ui:insert name="menuSelection"/>
    </ui:define>
    <ui:define name="body">
        <ui:insert name="body"/>
    </ui:define>
    <ui:define name="footer">
        <div class="footer">
            <ui:include src="footer.xhtml"/>
        </div>
    </ui:define>
</ui:composition>

最后,headertemplate.xhtml

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
            contentType="text/html">
     <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
       <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <body>
              <ui:insert name="body" />
            </body>
        </html>
</ui:composition>
为了简洁起见,我遗漏了许多xmlns行;我希望你明白这一点。

如何让DOCTYPE显示在呈现的页面中?

2 个答案:

答案 0 :(得分:7)

模板中移除<ui:composition>,即headertemplate.xhtml。它不属于那里。 <ui:composition>将删除标记之外的所有其他内容。

<!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">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    </head>
    <body>
        <ui:insert name="body" />
    </body>
</html>

请注意,模板定义文件(使用<ui:composition>的文件)中的doctype(和xml)声明是不必要的。只需删除它们。

另见:

答案 1 :(得分:1)

你必须记住一件事,即ui:composition标签以外的所有内容都被简单删除,因此你的案例中的 DOCTYPE 声明就会被忽略。

相关问题