4
votes

The wrong html output:

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

The main template:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:t="http://myfaces.apache.org/tomahawk"
      xmlns:c="http://java.sun.com/jsp/jstl/core"
      xmlns:a4j="http://richfaces.org/a4j"
      xmlns:rich="http://richfaces.org/rich"
      xmlns:fn="http://java.sun.com/jsp/jstl/functions">

  <h:head>
    <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
    <title><h:outputText value="dmw #{title}"/></title>
    <h:outputStylesheet library="#{uiSkin}" name="css/layout.css" />
    <h:outputStylesheet library="standard" name="css/developer.css"
                        rendered="#{developMode}" />

    ...
  </h:head>
  <h:body>

Example of a included page:

<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:ui="http://java.sun.com/jsf/facelets"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:f="http://java.sun.com/jsf/core"
  xmlns:t="http://myfaces.apache.org/tomahawk"
  xmlns:a4j="http://richfaces.org/a4j"
  xmlns:rich="http://richfaces.org/rich">
  <ui:composition>
  ...
</ui:composition>
</html>

Used Versions:

<jsf-api.version>2.1</jsf-api.version>
<jsf-impl.version>2.1.21</jsf-impl.version>
<richfaces.version>4.3.2.Final</richfaces.version> 
<prettyfaces.version>3.3.3</prettyfaces.version>
<tomahawk.version>1.1.14</tomahawk.version>

When i remove all ui:include and ui:insert tags everything is fine. I build a smaller Testproject which also works like suspected. The error seems to occur when a included page is loaded. A ui:insert tag which can´t be resolved doesn´t lead to the error. I think it has something to do with the rendering configuration.

I tried a few entries in faces-config but without sucess. The following entry removes the unwanted declaration but also the doctype.

<faces-config-extension>
 <facelets-processing>
  <file-extension>.xhtml</file-extension>
  <process-as>xml</process-as>
 </facelets-processing>
</faces-config-extension>

XML prolog / instruction not removed from XHTML output

I have no idea where it comes frome? Does anybody have a clue?

1

1 Answers

2
votes

If you use the 'xml' processing method for facelet files, the doctype is consumed during the process, alongside with the processing instructions. See the table in this answer: https://stackoverflow.com/a/10706157/801153.

To reapply the DOCTYPE tag, you can use the jsf h:doctype tag before the html. To do so you need to enclose the tags in a ui:composition tag, like this:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:ui="http://xmlns.jcp.org/jsf/facelets">

  <h:doctype rootElement="html" xmlns:h="http://java.sun.com/jsf/html" />

  <html lang="nl">

  ... page content ...

  </html>
</ui:composition>

The processing instruction and the DOCTYPE in this snippet apply to the .xhtml file source content, not the generated output. These must remain if you have your sourcefiles in xhtml format.

Alternatively you could experiment with the 'html5' type, as also specified in the table in the linked answer above. This would be useful if you have or create your sourcefiles as html5 files. This is the default processing method, when nothing is specified. This retains the doctype in a simplified version. However, this also passes any <?xml .. ?> processing instruction to the html output (your original issue). So you should then remove these processing instructions from your sourcefiles.