问题描述
我开始学习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
中<facelets-processing>
元素的配置. XML序言被描述为处理指令".在表中,您将看到仅在将模板作为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.
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节本身. 逃脱"是指 响应中的敏感内容会自动转义:例如,&
变为&
. 未逃脱"是指 此类内容无法转义.
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 &
, 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模板中?
- How to reference CSS / JS / image resource in Facelets template?
See also:
这篇关于未从XHTML输出中删除XML序言/指令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!