未从XHTML输出中删除XML序言/指令 [英] XML prolog / instruction not removed from XHTML output

查看:114
本文介绍了未从XHTML输出中删除XML序言/指令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始学习JavaServer Faces(JSF).我正在使用GlassFish 3+.我刚刚在NetBeans中创建了一个新的JSF项目并运行该项目.它工作正常,但是在检查XHTML输出时,我注意到保留了XML声明.这弄乱了DOCTYPE声明(通常应该在文档中首先出现).

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).

JSF应该删除XML声明,还是我做错了什么?

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

推荐答案

默认情况下,Facelets仅将其从合成文件(包括文件和合成组件)和标记文件中删除.不会将其从主模板中删除.自己删除即可.编写HTML时,您根本不应该使用XML序言.

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 facelets-processing元素

<facelets-processing>元素用于影响Facelets VDL文件的处理.因此,此设置 仅适用于达到Facelets ViewDeclarationLanguage实现的那些请求,具体说明如下: 通过javax.faces.FACELETS_VIEW_MAPPINGSjavax.faces.DEFAULT_SUFFIX运行时 <context-param>条目.该规范为Facelets文件定义了三种处理模式:Facelets XHTML 语法,XML View语法和Facelets JSPX语法.最后一种语法旨在简化向以下方面的Facelets迁移: 已经使用JSP文档语法(也称为JSPX语法)的应用程序.对文件处理的影响 下表中指定了这三种模式中的每一种.

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 

在上表中,通过"表示内容未经修改就直接传递给用户代理. 已消费"是指在服务器上以静默方式消费内容.请注意,对于CDATA部分, 即使应该使用开始和结束标记,也将通过CDATA节本身. 逃脱"是指 响应中的敏感内容会自动转义:例如,&变为&amp;. 未逃脱"是指 此类内容无法转义.

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.

换句话说,编写HTML5/XHTML时,必须自己删除它.实际上,更好的措词是:您不应在XML5和XHTML页面中自己包含XML序言,因为这不是必需的;它仅在XML和JSPX页面中是必需的(因此Facelets会自动将其删除).

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).

  • JavaServer Faces 2.2 and HTML5 support, why is XHTML still being used
  • Is it possible to use JSF+Facelets with HTML 4/5?

无关与具体问题无关,您应该使用<h:outputStylesheet>而不是<link rel="stylesheet">来独立于请求URL.

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" />

另请参见:

  • 如何引用CSS/JS/图像资源在Facelets模板中?
  • See also:

    • How to reference CSS / JS / image resource in Facelets template?
    • 这篇关于未从XHTML输出中删除XML序言/指令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆