5

Is it possible to tell Mojarra 2.2 which DocType to render in the resulting html pages?

It seems that it always renders the following HTML5 Doctype:

<!DOCTYPE html>

In our facelet template we use the following DocType declaration and we want to keep it in the generated HTML:

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

The template:

<?xml version='1.0' encoding='UTF-8' ?>
<!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"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html">

<h:body>
  <ui:insert name="content">Will be replaced</ui:insert>
</h:body>
</html>

The content:

<?xml version='1.0' encoding='UTF-8' ?>
<!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"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                template="/templates/standalone.xhtml">

    <ui:define name="content">
      <h:panelGroup>
        Foo
      </h:panelGroup>
    </ui:define>
</ui:composition>

The result:

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"><body>
        Foo
      </body>
</html>

I tried it with Mojarra 2.2.7 and 2.2.12 using GlassFish 4.1.

  • This is not the default behavior. So, it would be helpful if you tell the exact Mojarra version, include a single-file MVCE in the question (there's namely quite some ambiguity because you said there "template"), and/or in the meanwhile try the current latest version (2.2.12). – BalusC Jul 22 '15 at 07:50
  • I added an example and tried it with Mojarra 2.2.12 with the same result. – anotherUser Jul 22 '15 at 09:29
  • 1
    I reproduced it. This is indeed not the intented behavior. – BalusC Jul 22 '15 at 10:07

2 Answers2

1

I hit this bug when post-processing JSF generated content into PDF format. Also I noticed that using <h:doctype> results in two doctypes being generated.

Fortunately, mine being a post-processing concern, I can use String.replace("<!DOCTYPE html>", XHTML_DOCTYPE) to work around the problem. In a servlet environment you'd probably have to use a filter or wrap the HttpServletResponse to modify the doctype on the fly. Or you could fix the JSF implementation. That would make most sense.

Roger Keays
  • 3,117
  • 1
  • 31
  • 23
0

JIRA issue for this see this link: https://github.com/javaserverfaces/mojarra/issues/2824 and it has been closed as this is the expected behavior.

"The composite page is where you actually use the template. So it is the outer most file where you specified a doc type. As such it defines the doc type that will be rendered."

Just specify the DOCTYPE in a template and nowhere else

Kukeltje
  • 12,223
  • 4
  • 24
  • 47
user38156
  • 77
  • 5
  • I use the same DocType declaration in the template and the composite view. When the DocType declaration is removed from the composite view, then the result is still ` `. – anotherUser Jul 22 '15 at 08:39
  • Thanks for the link. The last comment of the issue https://java.net/jira/browse/JAVASERVERFACES-2820?focusedCommentId=372654 seems to relate to this problem. – anotherUser Jul 22 '15 at 11:42