简体   繁体   English

Eclipse 代码提示 JSP 与自定义标签 (taglib)

[英]Eclipse Code Hinting on JSP with Custom Tags (taglib)

I'm developing a JSP tag that have an attribute that works with a set of possible values.我正在开发一个 JSP 标记,该标记具有与一组可能值一起使用的属性。
I don't need to enforce this values, but I would like my IDE ( Eclipse ) do some code hinting or auto-completion.我不需要强制执行此值,但我希望我的 IDE ( Eclipse ) 执行一些代码提示或自动完成。

Suppose a tag like this <mytag:sometag someattribute="value" /> .假设像这样的标签<mytag:sometag someattribute="value" />

The attribute someattribute can have any value (remember, I don't need to enforce), but I would like it to suggest you the following list of values: ValueA , ValueB and ValueC属性someattribute可以有任何值(请记住,我不需要强制执行),但我希望它向您建议以下值列表: ValueAValueBValueC

Nitin Dahyabhai at the Eclipse Community Forums suggested writing a plugin based on org.eclipse.wst.xml.core.modelQueryExtensions or create templates with the values. Eclipse 社区论坛上的 Nitin Dahyabhai建议编写基于org.eclipse.wst.xml.core.modelQueryExtensions的模板的插件。

The problem with templates is that I have hundreds of possible values and I have multiple tags.模板的问题是我有数百个可能的值并且我有多个标签。
The problem with writing a plugin is that I haven't time or knowledge to do it.编写插件的问题是我没有时间或知识去做。

Is there another way to do it?还有另一种方法吗?

In case you end up with writing Eclipse extension for modelQueryExtensions, that should be as simple as:如果您最终为 modelQueryExtensions 编写 Eclipse 扩展,那么应该很简单:

Create new plug-in: com.my.taglib , and add to its plugin.xml :创建新插件: com.my.taglib ,并添加到其plugin.xml

<extension point="org.eclipse.wst.xml.core.modelQueryExtensions">
  <modelQueryExtension
    class="com.my.taglib.MyTaglibModelQueryExtension"
    contentType="org.eclipse.wst.html.core.htmlsource">
  </modelQueryExtension>
</extension>

Then implement com.my.taglib.MyTaglibModelQueryExtension class:然后实现com.my.taglib.MyTaglibModelQueryExtension class:

public class MyTaglibModelQueryExtension extends ModelQueryExtension {

    public String[] getAttributeValues(Element e, String namespace, String name) {
        // See XSDModelQueryExtension for an example implementation of this...
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM