Velocity Editor In Eclipse

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.

1 comment:

  1. I haven't tried extending VelocityServlet... Just never had the need to do it. I also haven't spent much time customizing things in Eclipse. So sorry to say, I don't have a solution to this problem.

    ReplyDelete

Comments on this blog are moderated and we do not accept comments that have links to other websites.

Share

About Isaac Sacolick

Isaac Sacolick is President of StarCIO, a technology leadership company that guides organizations on building digital transformation core competencies. He is the author of Digital Trailblazer and the Amazon bestseller Driving Digital and speaks about agile planning, devops, data science, product management, and other digital transformation best practices. Sacolick is a recognized top social CIO, a digital transformation influencer, and has over 900 articles published at InfoWorld, CIO.com, his blog Social, Agile, and Transformation, and other sites. You can find him sharing new insights @NYIke on Twitter, his Driving Digital Standup YouTube channel, or during the Coffee with Digital Trailblazers.