Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
801 views
in Technique[技术] by (71.8m points)

jsf 2 - XML prolog / instruction not removed from XHTML output

I'm starting to learn JavaServer Faces (JSF). I'm using GlassFish 3+. I've just created a new JSF project in NetBeans and run the project. It worked fine, but upon examining the XHTML output, I noticed the XML declaration was left in. This messes up the DOCTYPE declaration (which is always supposed to be first in the document).

enter image description here

Is JSF supposed to remove the XML declaration, or is there something I've done wrong?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Facelets will by default only remove it from compositions (include files and composite components) and tag files. It won't remove it from the master template. Just remove it yourself. You shouldn't be using the XML prolog at all when authoring HTML.

Whether the XML prolog will be removed from the master template is specified in appendix 1.1.1.1 of JSF 2.2 specification which describes the configuration of <facelets-processing> element in faces-config.xml. The XML prolog is described as "processing instructions". In the table, you'll see that it is only removed (consumed) when the template is processed as a XML or JSPX view.

1.1.1.1 The facelets-processing element

The <facelets-processing> element is used to affect the processing of Facelets VDL files. Therefore, this setting only applies to those requests that reach the Facelets ViewDeclarationLanguage implementation, as specified to the runtime via the javax.faces.FACELETS_VIEW_MAPPINGS and javax.faces.DEFAULT_SUFFIX <context-param> entries. The specification defines three processing modes for Facelets files: Facelets XHTML syntax, XML View syntax, and Facelets JSPX syntax. This last syntax is intended to ease the migration to Facelets for applications already using the JSP document syntax (also known as JSPX syntax). The affect on the processing of files in each of these three modes is specified in the following table.

Valid <process-as> values and their implications on the processing of Facelets.
-----------------------------------------------------------------------------------------
              <process-as>         <process-as>         <process-as>       <process-as>
              html5</process-as>   xhtml</process-as>   xml</process-as>   jspx</process-as>
              HTML 5 (default)     Facelets XHTML       XML View           Facelets JSPX
-----------------------------------------------------------------------------------------
XML Doctype   Simplified to        passed through       consumed           consumed
              <!DOCTYPE html>  

XML           passed through       passed through       consumed           consumed
declaration 

Processing    passed through       passed through       consumed           consumed
instructions

CDATA         passed through       passed through       consumed           consumed
section

Escaping of   escaped              escaped              escaped            not escaped
inline text    

XML           passed through       passed through       consumed           consumed
Comments 

In the preceding table, “passed through” means that the content is passed through unmodified to the user agent. “consumed” means the content is silently consumed on the server. Note that for CDATA sections, the content of the CDATA section itself is passed through, even if the start and end tags should be consumed. “escaped” means that sensivite content in the response is automatically escaped: & becomes &amp;, for example. “not escaped” means that such content is not escaped.

In other words, when you're authoring HTML5/XHTML, you have to remove it yourself. A better wording is actually: you shouldn't be including the XML prolog yourself in HTML5 and XHTML pages as that's not required; it's only required in XML and JSPX pages (and thus Facelets will automatically remove it).

See also:


Unrelated to the concrete problem, you should be using <h:outputStylesheet> instead of <link rel="stylesheet"> to be independent from the request URL.

<h:outputStylesheet name="css/default.css" />
<h:outputStylesheet name="css/cssLayout.css" />

See also:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...