JSF template: rendered page missing DOCTYPE

天涯浪子 提交于 2019-11-30 18:33:45

问题


TL;DR: I can't get the DOCTYPE header to appear on my JSF pages.

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.

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>

Then the ../layout/template.xhtml has:

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

And finally, the 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>

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

How can I get the DOCTYPE to show up in the rendered pages?


回答1:


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>

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

See also:

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



回答2:


You must remember one thing, that everything outside ui:compostion tags is simply cut out, so the DOCTYPE declaration in your case is simply ignored.



来源:https://stackoverflow.com/questions/7505219/jsf-template-rendered-page-missing-doctype

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!