Invisible comments in jsf 2.0? [duplicate]

和自甴很熟 提交于 2020-01-02 00:12:09

问题


is it possible to embed comments in my .xhtml-files that are only displayed in the source and not the rendered result? I want to include author, date,... in the files but they should not be visible to the enduser in the generated output. If I use the standard comment-tags <!-- --> the browser displays them.


回答1:


Add the following into your web.xml:

<context-param>
    <param-name>javax.faces.FACELETS_SKIP_COMMENTS</param-name>
    <param-value>true</param-value>
</context-param>

This way Facelets will skip the comments while parsing the view xhtml template.




回答2:


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

<ui:remove> This is a comment </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.

Examples of both comment options




回答3:


Wrong, the right way is:

<context-param>
    <param-name>facelets.SKIP_COMMENTS</param-name>  
    <param-value>true</param-value>  

This work for me, javax.faces.FACELETS_SKIP_COMMENTS no!



来源:https://stackoverflow.com/questions/3500738/invisible-comments-in-jsf-2-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!