Whenever I am working in a JSP file and I type ${
to start an el (Expression Language) tag, Eclipse will automatically add }
(with a space before the closing brace) after the cursor so that I get ${ }
instead of ${}
.
Is there a code template in Preferences that I can modify to change this behavior, or is it beyond user preference control?
I have checked in Preferences: Web: JSP Files: Editor: Templates, but none of those templates match. I've also looked in several other sections in Preferences but haven't found anything promising.
The Templates Preferences page is accessed from Window | Preferences | PHP | Templates . To remove a template from the list of available options, unmark its checkbox in the list. To edit an existing template, select it from the list and click Edit.
Click Ctrl+Space. The Content Assist box will appear, listing all available templates and completion options that begin with that combination of keys. Templates are marked in the content assist list with a blue square. Double-click the required template from the list.
What @Mero provided (see comments on answer above) might not be an exact answer, but creating a JSP Template probably the closest thing that I've found.
A few notes for anyone that wants to go that route:
Create a new template through menu Window->Preferences, then in the drill down menu navigate to Web->JSP Files->Editor->Templates. Click New.
Name is a shortcut you can type (the same way typing sysout ctrl+space
in Java is a shortcut for System.out.println()
). I suggest something simple like el
. This allows you to type e l ctrl-space
instead of $ { ctrl-space
to pull it up.
Context tells it when it should appear in intellisense. I suggest creating two of this template where one has a context of JSP Attribute value and the other has a context of All JSP.
Description is just informative. Put whatever you want. I put 'EL Script' myself.
Pattern is where you put what will be inserted. Put $${${cursor}}
or $${${script}}
, depending on preference. See below for explanation on the differences.
In Eclipse Templates ${}
is how you put variables in the template, so to make it actually print ${}
you have to escape the $
with a $$
leading to $${}
.
The predefined variable ${cursor}
defines where the cursor is after intellisense replaces the el
, so to have the cursor appear in between the curly braces you want to do this: $${${cursor}}
.
Using any variable that is not predefined (in this case, ${script}
) will simply put in that variable with a box around it and allow you to type over it and press enter when you're done, allowing you to move to the end of the closing curly brace.
Note: I understand that this is not an actual answer, but rather is a workaround. I'm putting it here simply so that those who are fine with a workaround can know how to go about doing it.
Edit
For those that don't like having to type ctrl-space
, a workaround could be to have the template name start with<
since on JSP pages, the <
opens the intellisense, so for instance, you could have the name be <el
or <$
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With