本文介绍了JSF模板:呈现的页面缺少DOCTYPE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

我刚刚继承了一个JSF 1.2项目,该项目在IE下存在一些显示问题.我是JSF的新手,但我认为问题出在以下事实中:呈现的页面(来自查看源")不包含正确的DOCTYPE.

I just inherited a JSF 1.2 project that's having some display issues under IE. I'm brand new to JSF, but I think the issues stem from the fact that the rendered pages (from "view source") do not contain a proper DOCTYPE.

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

The pages are composed of multiple parts, brought together using several layers of <ui:composition>. A typical page will look like:

<?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行;我希望你能明白.

I have left out many xmlns lines for brevity; I hope you get the idea.

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

推荐答案

从您的 master 模板(headertemplate.xhtml)中删除<ui:composition>.它不属于那里. <ui:composition>将剥离标签之外的所有其他内容.

Remove <ui:composition> from your master template, which is the headertemplate.xhtml. It doesn't belong there. The <ui:composition> will strip all other content outside the tag.

<!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)声明是不必要.只需删除它们即可.

Note that the doctype (and xml) declaration is unnecessary in template definition files (the ones using <ui:composition>). Just remove them.

  • How to include another XHTML in XHTML using JSF 2.0 Facelets?
  • Facelets 1.x docbook

这篇关于JSF模板:呈现的页面缺少DOCTYPE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-28 06:06