Search code examples
escapingfaceletsel

How to escape '$' and '#' in Facelets/EL?


I'm using Java Facelets and jQuery, however the expression

$('...')

in jQuery conflicts with EL expression, how do I escape the jQuery's one?

I'd like to escape a large chunk of Javascript, too.

ANSWERED

To convert the existing JSP to Facelets xhtml, it's convenient to just wrap the existing javascript by <![CDATA[ ... ]]>. However, the output scripts for <script> are wrapped by <!-- --> comment, which conflicts with CDATA section:

<script><![CDATA[ scripts... ]]></script>

=> <script><!-- <![CDATA[ scripts... ]]> --></script>

To resolve this problem, you should also comment out the CDATA:

<script>/* <![CDATA[ */ scripts... /* ]]> */</script>

=> <script><!-- /* <![CDATA[ */ scripts... /* ]]> */--></script>

See also When is a CDATA section necessary within a script tag?.


Solution

  • This should normally not conflict. EL uses ${} syntax. Anyway, you could either use jQuery() instead (the $() is just a shorthand) or simply put JS code in its own .js file.