6

When editing JSPs in Eclipse, the contents of <script> tags - i.e. Javascript code - is properly color coded and formated.

For reasons that go beyond the scope of this question, I have created a custom javascript tag, let's call it <sj:script>. The body of this type is pure javascript as you would have in a regular <script> tag.

However, when I have Javascript code within my custom tag, it is treated as simple text (no color coding, no proper indentation, etc).

My question is, how do I make Eclipse use a specific editor within custom JSP tags?

jd.
  • 4,057
  • 7
  • 37
  • 45
  • isn't the real question why do you need to define custom tags ? It seems a rather peculiar way to do things. – NimChimpsky Dec 08 '10 at 16:56
  • It is, I agree. But I'm developing a framework that works in a ... peculiar way – jd. Dec 08 '10 at 16:59
  • 1
    I've ended up in this exact same situation, and am presently [looking for an answer](http://stackoverflow.com/questions/19391634/is-there-wa-way-to-make-the-eclipse-wtp-jsp-editor-treat-the-body-fo-a-custom-ta). I'll post any findings here if I learn anything. – Jason Sperske Oct 15 '13 at 21:49

5 Answers5

1

You can try MyEclipse or Aptana Studio. They offer much better editors for web development.

But a much better approach is to put the JS into a different file and reference that with <script src="...">:

  1. You can use a better editor
  2. The browser can cache the JavaScript (instead of downloading it every time with the rest of the page)
  3. You can write tests for the JavaScript (next to impossible when the JS is held hostage in a JSP file).

[EDIT] Eclipse is open source. Download the code for the WTP project, look for the text editor parts and search for "script". In all places that you find, add "sj:script", too.

Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820
  • Thanks for the answer, but that works well for me already. All I need now is to go the extra mile and have 'inline' custom javascript properly handled in eclipse properly. – jd. Dec 08 '10 at 17:01
0

Have you included the Tag Library Descriptor file in the jsp where you are using the custom tag?

Colm Ryan
  • 1,208
  • 2
  • 14
  • 12
  • Yes, but that wouldnt tell eclipse that the content is Javascript and that a javascript editor should be used for content within this tag. – jd. Dec 02 '10 at 19:21
0

I have a list of plugins for eclipse which enable eclipse to edit JS files:

http://www.delicious.com/powtac/javascript+eclipse

Just go trough the links and see the different descriptions how to install them.

powtac
  • 40,542
  • 28
  • 115
  • 170
  • Thanks for the answer, but I don't have a problem when editing .js files (the Eclipse editor is good enough for me). My problem is when I am within a JSP file (that contains HTML markup), I want eclipse to switch to 'javascript' mode for text within my custom tags. – jd. Dec 02 '10 at 19:23
0

AFAIK, editors are chosen based on file extension, and there's no mechanism to customize this based on particular content inside the file.

I see 2 options

  • Creating a custom text editor to take into account your custom script tag (probably not worth the effort)
  • Put your javascript snippet in an external file, use the include directive inside your custom script tag.

        <%@ include file="javascript.js" %> 
    
ddewaele
  • 22,363
  • 10
  • 69
  • 82
  • would there be simple way of creating a custom text editor that extends from the default text editor, only adding the rule for my custom tag? – jd. Dec 03 '10 at 19:22
  • I don't know how comfortable you are with java development in general and eclipse development in particular but i would classify it as being moderately complex. Offcourse you can have a look at the default editor and start extending that. However, i would opt for the second option – ddewaele Dec 03 '10 at 20:37
  • The second option doesn't help me much, I know I am able to do that. Thanks for the thought. – jd. Dec 04 '10 at 07:55
0

Eclipse has a template feature where in you can add specific tag ,which can be made available for all JSP pages.

Ensure you have installed Eclipse WTP ( Web Tools Platform )

1.Open Preferences window [ Select Window > Preferences ] 2.Expand Web Option from the menu, upon which you can see [ CSS Files,HTML Files etc.. 3.Select JSP Files 4.Select Editor 5.Select Templates 6.In the corresponding pane , click New and from there rest can be easily done.

Ratna Dinakar
  • 1,573
  • 13
  • 16
  • thanks for you're answer, but I don't see how this helps me. I think the settings you pointed me to allows you to define snipets of code that get generated automatically on certian comands... or did I miss something ? – jd. Dec 06 '10 at 23:12
  • I guess,its same way. Can you give more information like where you are putting TLD files etc. – Ratna Dinakar Dec 07 '10 at 06:34