Reputation: 71
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.
Upvotes: 5
Views: 1481
Reputation: 87
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
Upvotes: 0
Reputation: 3247
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.
Upvotes: 1