JSF2 XHTML facelets comments appearing in output

Having jumped in at the deepend with JSF2 recently I noticed that adding comments to my facelets pages using the standard HTML commenting syntax:

<!-- comment here -->

actually results in the comment being sent as part of the output stream to the browser.

This is very annoying because I’ve generally put the comments in the xhtml for maintenance purposes so I don’t want anyone who views the source to see them; also they can actually be interpreted by JSF component libraries and add rendered output which you didn’t expect (such as extra rows in auto generated tables).

Thankfully JSF2 has a handy setting to stop comments being sent in the output stream. In your project web.xml file simply add the following to your web-app section:

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

Comments should no longer make it to the output stream.

Advertisements
This entry was posted in JSF2, Software Engineering and tagged , , , . Bookmark the permalink.

One Response to JSF2 XHTML facelets comments appearing in output

  1. Ian Roberts says:

    That’s normal in JSP (and GSP, which is where I spend much of my time these days), and quite reasonable as JSPs aren’t always used to render HTML. There’s a separate comment syntax to comment stuff out at the JSP level rather than the HTML level.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s