Question

I'm trying to output an HTML5 compliant page but JSF produces an XML prolog. How can I prevent this?

index.xhtml

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    template="/WEB-INF/templates/layout.xhtml">

</ui:composition>

layout.xhtml

<!DOCTYPE html>
<html xmlns:h="http://java.sun.com/jsf/html"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core">
<f:view locale="#{userContext.locale}">
    <h:head>
        ...
    </h:head>
    <h:body>
        ...
    </h:body>
</f:view>
</html>

Generated output

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html><head>...

I'm using Mojarra 2.2.5.

Was it helpful?

Solution

I understood the problem. I simplified the above example but I was also including composite components the following way:

index.xhtml

<ui:composition template="/WEB-INF/templates/layout.xhtml"
...
      xmlns:myapp="http://myapp.com/jsf/core">

myapp composite

<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:composite="http://java.sun.com/jsf/composite"
    xmlns:p="http://primefaces.org/ui">
...

Unfortunately, one of the composite file in myapp was declaring an XML prolog. For a reason I don't understand, the use of a composition declaring an XML prolog had the effect to add the XML prolog to the main file.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top