有没有办法使Eclipse WTP JSP编辑器将自定义TagLib的主体视为JavaScript? [英] Is there way to make the Eclipse WTP JSP editor treat the body of a custom TagLib as JavaScript?

查看:89
本文介绍了有没有办法使Eclipse WTP JSP编辑器将自定义TagLib的主体视为JavaScript?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经编写了一个简单的taglib(称为Script),它将主体的内容包装到HTML <script>元素中,并将其插入外部taglib的底部(称为Body).这是为了自动初始化 Zurb's Foundation 4 .这意味着该JSP:

I've written a simple taglib (called Script) that takes its body's content, wraps it in an HTML <script> element and inserts it at the bottom of an outer taglib (called Body). This is to automate the initialization of Zurb's Foundation 4. This means this JSP:

<r:page>
  <r:head title='Test Site'/>
  <r:body>
    <div id='thing'></div>
    <r:script>
      $(function() {
        $('#thing').html('DOM is ready');
      });
    </r:script>
  </r:body>
</r:page>

呈现为以下HTML:

<!DOCTYPE html>
<!--[if IE 8]><html class='no-js lt-ie9' lang='en'><![endif]-->
<!--[if gt IE 8]><!--><html class='no-js' lang='en'><!--<![endif]-->
  <head>
    <meta http-equiv='content-type' content='text/html;charset=UTF-8' />
    <title>Test Site</title>
    <meta name='viewport' content='width=device-width, initial-scale=1, maximum-scale=1'>
    <link rel='stylesheet' href='/css/foundation.min.css'>
    <script src='/js/vendor/custom.modernizr.js'></script>
    <!--[if lt IE 9]><script src='http://html5shiv.googlecode.com/svn/trunk/html5.js'></script><![endif]-->
  </head>
  <body>
    <div id='thing'></div>
    <script>
      document.write('<script src=/js/vendor/' + ('__proto__' in {} ? 'zepto' : 'jquery') + '.js><\/script>')
    </script>
    <script src='/js/foundation.min.js'></script>
    <script>
      $(document).foundation();
      //The contents of the <r:script> from the JSP
      $(function() {
        $('#thing').html('DOM is ready');
      });
    </script>
  </body>
</html>

现在,这种方法的缺点是Eclipse WTP JSP编辑器将脚本taglib的主体内容视为更多HTML,因此我失去了JavaScript语法高亮显示的功能.是否有某种方法(可能是通过向.tld文件中添加信息或创建TagInfo类来告诉JSP编辑器主体是要读取JavaScript的方法?还是仅添加<script></script>的唯一方法)手动设置元素(为清楚起见,将自定义taglib重命名为onFoundationReady之类的名称.)同样,以防万一仍然有可能说服比我自己聪明的人,首先值得付出额外的努力,在每页底部都包含样板Zepto/jQuery加载器和$(document).foundation();,并且当包括我也在通过JavaScript SDK使用Facebook Connect的事实时,有很多样板代码可以使此taglib完全隐藏我)

Now the downside to this approach is that the Eclipse WTP JSP Editor sees the body contents of the script taglib as just more HTML, so I lose JavaScript syntax highlighting. Is there some way (possibly by adding information to the .tld file or creating a TagInfo Class to tell the JSP editor that the body is mean to be read a JavaScript? or is the only approach to just add a <script></script> element by hand (and for clarity sake rename the custom taglib something like onFoundationReady). Also just in case it's still possible to to convince smarter people than myself that this extra effort is worth it in the first place, the alternative would be to include the boilerplate Zepto/jQuery loader and $(document).foundation(); at the bottom of each page, and when include the fact that I'm also using Facebook Connect via the JavaScript SDK there is a lot of boiler plate code that this taglib is cleanly hiding from me)

推荐答案

是,不是. JSP规范中没有任何内容可以传达有关标签正文内容的任何相关信息,除了像页面的其余部分一样处理或将其视为放手"之外,编辑者可以使用该标签的正文内容.

Yes and no. There's nothing in the JSP specification that conveys any relevant information about the body content of the tag that the editor can use beyond processing it like the rest of the page or treating it as "hands off."

可以对WTP进行更改,使可能允许另一个 Eclipse插件来确定该区域的语法颜色,但是我真的不知道那个特定的功能值得付出努力.

Changes could be made to WTP that might allow another Eclipse plug-in to determine syntax coloring for that region, but I really don't know if that one specific feature is something worth the effort involved.

这篇关于有没有办法使Eclipse WTP JSP编辑器将自定义TagLib的主体视为JavaScript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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