如何在Facelets / EL中逃脱'$'和'#'? [英] How to escape '$' and '#' in Facelets/EL?

查看:141
本文介绍了如何在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 use jQuery() instead (the $() is just a shorthand) or simply put JS code in its own .js file.

这篇关于如何在Facelets / EL中逃脱'$'和'#'?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆