We are using
Velocity Web Edit in Eclipse to edit our velocity templates. It leads to some nice development procedures.
1) Whenever you're creating or editing a vm file, make sure that you have the Eclipse editor open the .vm file and have an editor open to the class (in our case, Action class since we're using Struts).
2) When you add a new object to the context, you can make Eclipse aware of the object. Just click on the Context tab (on the vm file's editor window, it will be in the bottom left hand corner) and add the name/class of the object.
3) This will help you keep the editor for the .vm file and your action class (or whatever you're using to fill the context) in sync. You'll now be able to use Eclipse's autocomplete features on your context objects.
One gotcha: VelocityWebEdit doesn't seem to know about generics. You can add a collection to the context and have VWE recognize this collection, but you won't be able to do an autocomplete on the objects that make up your collection.
Here is an easy work around. Let's say you have a ArrayList
that you add to the VelocityContext under the name 'lstStrings'.
1) Open the context tab for the vm file
2) Add 'lstStrings' as a 'java.util.ArrayList'
3) Add 'strObj' as a 'java.lang.String'
Then, when you need to loop over your array, use 'strObj' as you're looping variable. Since you told VWE that strObj is a String, you'll be able to use the autocomplete features on this object.
continue reading "Velocity Editor In Eclipse"