如何在Facelets / EL中逃脱'$'和'#'? [英] How to escape '$' and '#' in Facelets/EL?
问题描述
我正在使用Java Facelets和jQuery,但是表达式
$('...')$ b $ jQuery与EL表达式冲突,我如何避免jQuery的一个?$>
。但是,
$ p
$ b $ p
我也想逃避大量的Javascript。
解答
要将现有的JSP转换为Facelets xhtml,只需将<![CDATA [...]]>
< script>
的输出脚本由<! - - >
注释包装,它与CDATA部分冲突:< script><![CDATA [scripts ...]]> /脚本>
=> < script><! - <![CDATA [scripts ...]]> - >< /脚本>
要解决此问题,您还应该注释出CDATA:
< script> / *<![CDATA [* / scripts ... / *]]> * /< /脚本>
=> < script><! - / *<![CDATA [* / scripts ... / *]]> * / - >< /脚本>
另请参见什么时候在脚本标签中需要CDATA部分?。
解决方案这通常不会冲突。 EL使用
$ {}
语法。无论如何,您可以使用jQuery()
相反($()
只是一个简写),或者简单地将JS代码放在自己的.js
文件中。 / p>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?.
解决方案This should normally not conflict. EL uses
${}
syntax. Anyway, you could either usejQuery()
instead (the$()
is just a shorthand) or simply put JS code in its own.js
file.这篇关于如何在Facelets / EL中逃脱'$'和'#'?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!