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

查看:26
本文介绍了未从 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.

JSF 2.2 规范,它描述了 faces-config.xml 元素的配置>.XML prolog 被描述为处理指令".在该表中,您将看到它仅在模板作为 XML 或 JSPX 视图处理时才被删除(使用).

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.

元素用于影响 Facelets VDL 文件的处理.因此,这个设置仅适用于那些到达 Facelets ViewDeclarationLanguage 实现的请求,如指定的那样运行时通过 javax.faces.FACELETS_VIEW_MAPPINGSjavax.faces.DEFAULT_SUFFIX 条目.该规范为 Facelets 文件定义了三种处理模式: Facelets XHTML语法、XML 视图语法和 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 

在上表中,passed through"是指内容未经修改地直接传递给用户代理.已消费"意味着内容在服务器上以静默方式消费.请注意,对于 CDATA 部分,CDATA 部分本身会被传递,即使应该使用开始和结束标记.逃脱"的意思是响应中的敏感内容会自动转义:例如,& 变为 &.没有逃脱"的意思是此类内容不会被转义.

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 时,您必须自己将其删除.更好的措辞实际上是:您不应该自己在 HTML5 和 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).

与具体问题无关,您应该使用 而不是 code> 独立于请求 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" />

另见:

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