jd.
jd.

Reputation: 4098

Configure Eclipse to use Javascript editor

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?

Upvotes: 6

Views: 6111

Answers (5)

Aaron Digulla
Aaron Digulla

Reputation: 328536

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.

Upvotes: 1

Ratna Dinakar
Ratna Dinakar

Reputation: 1573

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.

Upvotes: 0

ddewaele
ddewaele

Reputation: 22603

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" %> 
    

Upvotes: 0

powtac
powtac

Reputation: 41040

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.

Upvotes: 0

Colm Ryan
Colm Ryan

Reputation: 1208

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

Upvotes: 0

Related Questions