Massimo Caliman
by Massimo Caliman
~1 min read

Categories

  • Java

Tags

  • code
  • en
  • java
  • jsf

Granted, it is always possible to use the classic comment tags <!-- and --> in HTML, but these are rendered by default. In case the commented code is a hidden feature for the next (not yet official) release, or a part of EL or JSF tags, this could be awkward, if not a security hole.

Essentially, there are two methods. Let’s look at them:

1. Set facelets.SKIP_COMMENTS

In our application’s web.xml file, we set the facelets.SKIP_COMMENTS parameter to true:

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

Be careful though: no HTML comments will be rendered, and sometimes we want to have more control over which comments to expose or not (some might be useful).

2. Using the ui:remove tag

The ui:remove tag is the one for me. I use it often, and it gives me all the flexibility and security that enterprise applications require. The usage is trivial, and you can see an example below:

<ui:remove>
  <!-- This comment will also not be rendered -->
  <h:commandButton type="button" value="#{msg.buttonLabel}" />
</ui:remove>

What is delimited by the tag will be treated as a comment by a compiler.