【问题标题】:JSF template: rendered page missing DOCTYPEJSF 模板:呈现的页面缺少 DOCTYPE
【发布时间】:2011-11-22 05:50:25
【问题描述】:

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>

那么../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 显示在呈现的页面中?

【问题讨论】:

    标签: jsf facelets


    【解决方案1】:

    从您的 ma​​ster 模板中删除 &lt;ui:composition&gt;,即headertemplate.xhtml。它不属于那里。 &lt;ui:composition&gt; 将删除标签之外的所有其他内容。

    <!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>
    

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

    另见:

    【讨论】:

      【解决方案2】:

      您必须记住一件事,ui:compostion 标记之外的所有内容都被简单地删除了,因此您的情况中的 DOCTYPE 声明将被简单地忽略。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-09-27
        • 1970-01-01
        • 2013-02-18
        • 2010-10-25
        • 2012-04-28
        • 2012-12-08
        • 2015-06-27
        • 1970-01-01
        相关资源
        最近更新 更多