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

Geo*_*old 3 jsf facelets

TL; DR:我无法将DOCTYPE标头显示在我的JSF页面上.

我刚刚继承了一个JSF 1.2项目,它在IE下有一些显示问题.我是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>
Run Code Online (Sandbox Code Playgroud)

然后../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>
Run Code Online (Sandbox Code Playgroud)

最后,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>
Run Code Online (Sandbox Code Playgroud)

xmlns为简洁起见,我遗漏了很多行; 我希望你明白这个主意.

如何让DOCTYPE显示在渲染页面中?

Bal*_*usC 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>
Run Code Online (Sandbox Code Playgroud)

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

也可以看看: