JSF 2 removes xml declaration in rendered release

Invalid 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 the 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 delete all ui: include and ui: insert tags, everything is fine. I am building a smaller Testproject, which also works as intended. An error occurs when the included page loads. The ui: insert icon, which cannot be resolved, does not result in an error. I think this has something to do with setting the rendering.

I tried a few entries in faces-config, but without sucess. The following entry removes the unwanted ad as well as the doctype.

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

XML prolog / command not removed from XHTML output

I don’t know where it came from? Somebody knows?

+4
source share
1 answer

If you use the "xml" processing method for facial shape files, the process uses doctype along with processing instructions. see the table in this answer: fooobar.com/questions/438187 / ....

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

 <?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 DOCTYPE in this fragment apply to the original contents of the .xhtml file, and not to the generated output. They should stay if you have xhtml source files.

Alternatively, you can experiment with the type "html5", as also indicated in the table in the linked answer above. This would be useful if you have or create your source files as html5 files. This is the default processing method when nothing is specified. This saves the document type in a simplified version. However, this also passes any processing instruction <?xml .. ?> html output (original problem). Therefore, you should remove these processing instructions from your source files.

+1
source

Source: https://habr.com/ru/post/1491128/


All Articles