jsf 2.0 中看不见的注释?
是否可以在我的 .xhtml 文件中嵌入注释,这些注释仅显示在源代码中,而不显示在渲染结果中?
我想在文件中包含作者、日期...,但最终用户在生成的输出中不应该看到它们。如果我使用标准注释标签 浏览器会显示它们。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
是否可以在我的 .xhtml 文件中嵌入注释,这些注释仅显示在源代码中,而不显示在渲染结果中?
我想在文件中包含作者、日期...,但最终用户在生成的输出中不应该看到它们。如果我使用标准注释标签 浏览器会显示它们。
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(3)
将以下内容添加到您的
web.xml
中:这样,
Facelets
将在解析视图xhtml
模板时跳过注释。Add the following into your
web.xml
:This way
Facelets
will skip the comments while parsing the viewxhtml
template.JSF 中的不可见注释是一个缺点,特别是对于初学者而言。我同意明切夫先生的回答。无论如何,我提供了一种在 JSF 中注释内容的替代方法,其中包括使用 ui:remove
UI 删除标记用于指定应由 Facelets 视图处理程序从页面中删除的标记或内容块在编译时。该标签没有属性。您可以使用此标记来指示应从呈现的页面中删除特定标记。
删除设计时期间所需的内容很有用,但在运行期间则不然时间,例如评论、一些存根内容(例如“lorem ipsum”),这些内容有助于填充页面内容以适合视觉设计器(例如 Dreamweaver)等中的布局。
请参阅:Facelets ui:remove tag 的实际影响
请注意,Facelets 编译过程比 JSP 编译快得多 因为当您第一次访问页面时,实际上并没有在幕后生成和编译 Java 字节码。 UI 删除标记用于指定 Facelets 视图处理程序在编译时应从页面中删除的标记或内容块。该标签没有属性。
Invisible comments in JSF is a drawback, specially for beginers. I agree with answer of Mr Minchev. Anyway, I provide an alternative way to comment content in JSF consisting of using ui:remove
The UI Remove tag is used to specify tags or blocks of content that should be removed from your page by the Facelets view handler at compile time. This tag has no attributes. You can use this tag to indicate that a particular tag should be removed from the rendered page.
It's useful to remove content which is required during design time, but not during run time, such as comments, some stubbed content (e.g. "lorem ipsum") which aids in filling up the page content to fit the layout in visual designers such as Dreamweaver, etc.
See: Practical implications of Facelets ui:remove tag
Note that the Facelets compilation process is much faster than the JSP compilation process because no Java bytecode is actually generated and compiled behind the scenes when you first visit your page. The UI Remove tag is used to specify tags or blocks of content that should be removed from your page by the Facelets view handler at compile time. This tag has no attributes.
错误的是,正确的做法是:
这对我有用,javax.faces.FACELETS_SKIP_COMMENTS 不!
Wrong, the right way is:
This work for me, javax.faces.FACELETS_SKIP_COMMENTS no!