posted 11 years ago
1. Use the "jQuery()" function instead of the "$" shorthand. It's possible to use "$", but only if you're very careful, since "$" is the EL marker for read-only variables in the same way that "#" is the marker for references (read/write variables and so forth).
2. When coding JavaScript on a JSF View Template, wrap the <script> element with a f:verbatim element (not strictly necessary anymore, but good practice). Use the XML "CDATA" convention to keep the XML processor from getting confused by any <, > ' " or & characters it encounters in the script. That is:
Note that the "type" attribute for the HTML SCRIPT element is deprecated, though and you should omit it. Also note the "//" before the CDATA end so that JavaScript will see that stuff as a comment and not attempt to interpret it as part of the script.
Alternatively - and preferably - move the script to a separate ".js" resource and use the JSF script reference element to point to it. The .js file doesn't need all that escaping. And the "$" should work there as well.
The problem with getting rid of the "undesirables" is that sooner or later someone will decide that YOU are an undesirable.