部分应如何在JSF中查看? HTML5或XHTML?

时间:2022-11-06 20:09:43

It's just a curiosity I'm having right now. In Eclipse this is the <head> section that came defined on a New Facelet Template for instance, but for the most template is the same thing :

这只是我现在的好奇心。在Eclipse中,这是在新的Facelet模板上定义的部分,但是对于大多数模板来说都是一样的:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets">
<head>
  ..
</head>

I would like to user a more clear code on it, so I change to :

我想在其上使用更清晰的代码,所以我改为:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets">
<head>
  ..
</head>

It works fine in development, but I was wondering if this kind of approach would give any problem in the future, through the many browsers or device (mobile).

它在开发中运行良好,但我想知道这种方法是否会在未来通过许多浏览器或设备(移动)提出任何问题。

2 个解决方案

#1


15  

That's the HTML5 doctype and it should work just fine in all browsers, including IE6.

这是HTML5文档类型,它应该在所有浏览器中都能正常工作,包括IE6。

JSF is officially specified to produce XHTML 1.0 compliant markup (with here and there only a few violations in the implementations which is fixed in JSF 2.2 and/or are manageable by context params). JSF can by design not produce non-XML sytnax (e.g. <br> instead of <br/>) and therefore the old HTML4 doctype is in no way compatible with JSF-produced HTML output (that is, when you respect the standards and/or fear the W3 validator; however, most if not all browsers are very forgiving on it). In contrary to the old HTML4 doctype, the HTML5 doctype allows XML syntax and is therefore compatible with XHTML doctypes. JSF pages can therefore be authored with HTML5 doctype.

官方指定JSF生成符合XHTML 1.0标记(此处和实现中只有少数违规,在JSF 2.2中修复和/或可由上下文参数管理)。 JSF可以设计不生成非XML sytnax(例如
而不是
),因此旧的HTML4 doctype与JSF生成的HTML输出完全兼容(也就是说,当你尊重标准和/时或担心W3验证器;但是,大多数(如果不是所有浏览器)都非常宽容它)。与旧的HTML4 doctype相反,HTML5 doctype允许XML语法,因此与XHTML doctypes兼容。因此,可以使用HTML5 doctype创建JSF页面。

The doctype is only of importance for how the webbrowser interprets and presents the HTML markup (as produced by JSF in your specific case, but the HTML does not necessarily need to be produced by JSF and thus browser's presentation is technically completely unrelated to JSF). Escpecially Microsoft IE has a major problem with certain doctypes or a complete lack of doctype. At the bottom of this page you can find a concise overview of browser behaviour in combination with certain doctypes. There are three standard behaviours:

doctype仅对webbrowser如何解释和呈现HTML标记非常重要(由JSF在您的特定情况下生成,但HTML不一定需要由JSF生成,因此浏览器的表示在技术上与JSF完全无关)。特别是Microsoft IE在某些文档类型或完全缺乏doctype方面存在严重问题。在本页底部,您可以结合某些文档类型找到浏览器行为的简明概述。有三种标准行为:

  • Q - Quirksmode. You really don't want to have that. It triggers box model bug in IE. The CSS width and height then incorrectly covers the padding and border.
  • 问 - Quirksmode。你真的不想拥有它。它触发IE中的盒子模型错误。然后CSS宽度和高度错误地覆盖填充和边框。

  • A - Almost standards mode. Affordable, only vertical sizing of table cells is not as per CSS2 spec. Useful if you want to avoid mysterious gaps of images in table cells.
  • A - 几乎标准模式。经济实惠,只有表格单元的垂直尺寸不符合CSS2规范。如果你想避免表格单元格中神秘的图像间隙,这很有用。

  • S - Standards mode. Browser tries to be fully w3 HTML/CSS standard compliant. Preferred mode since it's the only mode you can be less or more certain that your website will look exactly the same in all browsers.
  • S - 标准模式。浏览器尝试完全符合HTML / CSS标准。首选模式,因为它是唯一的模式,您可以更少或更确定您的网站在所有浏览器中看起来完全相同。

In your particular case, with the change from XHTML 1.0 transitional doctype to HTML5 doctype, Firefox, Chrome, Safari and IE>=8 will go from "A" to "S". So, you should definitely review the browser's presentation of your website as to padding of images in table cells if you intend a pixel-perfect design.

在您的特定情况下,随着从XHTML 1.0过渡文档类型到HTML5文档类型的更改,Firefox,Chrome,Safari和IE> = 8将从“A”变为“S”。因此,如果您打算使用像素完美的设计,那么您一定要查看浏览器的网站演示文稿,了解表格单元格中的图像填充。

As to the importance of the doctype in IE, here's a piece of HTML which demonstrates the box model bug triggered by "Q" in IE6-9 (note that this does not manifest in IE10 anymore):

关于doctype在IE中的重要性,这里有一段HTML,它演示了IE6-9中由“Q”触发的盒子模型错误(请注意,这在IE10中不再显示):

<!DOCTYPE html>
<html lang="en">
    <head>
        <title>Remove DOCTYPE to trigger quirksmode</title>
        <style>
            #box { 
                background: yellow; 
                width: 100px;
                padding: 20px; 
                border: 20px solid black; 
                margin: 20px;
            }
        </style>
    </head>
    <body>
        <div id="box">box</div>
    </body>
</html>

Copy'n'paste'n'run it. With <!DOCTYPE html> present, you'll see a rectangle. Without the doctype line you'll see a genuine square (in IE10 you need in the webdeveloper toolset (press F12) to change the "Browser mode" to e.g. IE9 in order to see it).

Copy'n'paste'n'run它。当存在时,您将看到一个矩形。如果没有doctype行,您将看到一个真正的正方形(在IE10中,您需要在webdeveloper工具集中(按F12)将“浏览器模式”更改为例如IE9才能看到它)。

部分应如何在JSF中查看? HTML5或XHTML?

See also:

#2


1  

The best solution would be to use the detailed declaration only once in the index template and include the header & body templates there. If that's not possible, you can leave this declaration away. It's "standard", but not really necessary!

最好的解决方案是在索引模板中仅使用详细声明一次,并在其中包含标题和正文模板。如果那是不可能的,你可以放弃这个声明。这是“标准”,但并非真正必要!

#1


15  

That's the HTML5 doctype and it should work just fine in all browsers, including IE6.

这是HTML5文档类型,它应该在所有浏览器中都能正常工作,包括IE6。

JSF is officially specified to produce XHTML 1.0 compliant markup (with here and there only a few violations in the implementations which is fixed in JSF 2.2 and/or are manageable by context params). JSF can by design not produce non-XML sytnax (e.g. <br> instead of <br/>) and therefore the old HTML4 doctype is in no way compatible with JSF-produced HTML output (that is, when you respect the standards and/or fear the W3 validator; however, most if not all browsers are very forgiving on it). In contrary to the old HTML4 doctype, the HTML5 doctype allows XML syntax and is therefore compatible with XHTML doctypes. JSF pages can therefore be authored with HTML5 doctype.

官方指定JSF生成符合XHTML 1.0标记(此处和实现中只有少数违规,在JSF 2.2中修复和/或可由上下文参数管理)。 JSF可以设计不生成非XML sytnax(例如
而不是
),因此旧的HTML4 doctype与JSF生成的HTML输出完全兼容(也就是说,当你尊重标准和/时或担心W3验证器;但是,大多数(如果不是所有浏览器)都非常宽容它)。与旧的HTML4 doctype相反,HTML5 doctype允许XML语法,因此与XHTML doctypes兼容。因此,可以使用HTML5 doctype创建JSF页面。

The doctype is only of importance for how the webbrowser interprets and presents the HTML markup (as produced by JSF in your specific case, but the HTML does not necessarily need to be produced by JSF and thus browser's presentation is technically completely unrelated to JSF). Escpecially Microsoft IE has a major problem with certain doctypes or a complete lack of doctype. At the bottom of this page you can find a concise overview of browser behaviour in combination with certain doctypes. There are three standard behaviours:

doctype仅对webbrowser如何解释和呈现HTML标记非常重要(由JSF在您的特定情况下生成,但HTML不一定需要由JSF生成,因此浏览器的表示在技术上与JSF完全无关)。特别是Microsoft IE在某些文档类型或完全缺乏doctype方面存在严重问题。在本页底部,您可以结合某些文档类型找到浏览器行为的简明概述。有三种标准行为:

  • Q - Quirksmode. You really don't want to have that. It triggers box model bug in IE. The CSS width and height then incorrectly covers the padding and border.
  • 问 - Quirksmode。你真的不想拥有它。它触发IE中的盒子模型错误。然后CSS宽度和高度错误地覆盖填充和边框。

  • A - Almost standards mode. Affordable, only vertical sizing of table cells is not as per CSS2 spec. Useful if you want to avoid mysterious gaps of images in table cells.
  • A - 几乎标准模式。经济实惠,只有表格单元的垂直尺寸不符合CSS2规范。如果你想避免表格单元格中神秘的图像间隙,这很有用。

  • S - Standards mode. Browser tries to be fully w3 HTML/CSS standard compliant. Preferred mode since it's the only mode you can be less or more certain that your website will look exactly the same in all browsers.
  • S - 标准模式。浏览器尝试完全符合HTML / CSS标准。首选模式,因为它是唯一的模式,您可以更少或更确定您的网站在所有浏览器中看起来完全相同。

In your particular case, with the change from XHTML 1.0 transitional doctype to HTML5 doctype, Firefox, Chrome, Safari and IE>=8 will go from "A" to "S". So, you should definitely review the browser's presentation of your website as to padding of images in table cells if you intend a pixel-perfect design.

在您的特定情况下,随着从XHTML 1.0过渡文档类型到HTML5文档类型的更改,Firefox,Chrome,Safari和IE> = 8将从“A”变为“S”。因此,如果您打算使用像素完美的设计,那么您一定要查看浏览器的网站演示文稿,了解表格单元格中的图像填充。

As to the importance of the doctype in IE, here's a piece of HTML which demonstrates the box model bug triggered by "Q" in IE6-9 (note that this does not manifest in IE10 anymore):

关于doctype在IE中的重要性,这里有一段HTML,它演示了IE6-9中由“Q”触发的盒子模型错误(请注意,这在IE10中不再显示):

<!DOCTYPE html>
<html lang="en">
    <head>
        <title>Remove DOCTYPE to trigger quirksmode</title>
        <style>
            #box { 
                background: yellow; 
                width: 100px;
                padding: 20px; 
                border: 20px solid black; 
                margin: 20px;
            }
        </style>
    </head>
    <body>
        <div id="box">box</div>
    </body>
</html>

Copy'n'paste'n'run it. With <!DOCTYPE html> present, you'll see a rectangle. Without the doctype line you'll see a genuine square (in IE10 you need in the webdeveloper toolset (press F12) to change the "Browser mode" to e.g. IE9 in order to see it).

Copy'n'paste'n'run它。当存在时,您将看到一个矩形。如果没有doctype行,您将看到一个真正的正方形(在IE10中,您需要在webdeveloper工具集中(按F12)将“浏览器模式”更改为例如IE9才能看到它)。

部分应如何在JSF中查看? HTML5或XHTML?

See also:

#2


1  

The best solution would be to use the detailed declaration only once in the index template and include the header & body templates there. If that's not possible, you can leave this declaration away. It's "standard", but not really necessary!

最好的解决方案是在索引模板中仅使用详细声明一次,并在其中包含标题和正文模板。如果那是不可能的,你可以放弃这个声明。这是“标准”,但并非真正必要!