views:

3980

answers:

10

I've taken quite a shine to the Spring Framework and would like to get into it a bit more. I have noticed that aside from plain vanilla JSPs there are various template engines for use with Spring MVC, such as Velocity and Freemarker. Are there others? Which one do you recommend?

+1  A: 

When you say Spring Framework are you referring to Spring MVC or just the core Spring concepts (dependency injection, AOP, etc)?

If it is really the concept of Spring you like then I recommend checking out Stripes. Stripes makes using Spring dependency injection really easy and offers a lot in the way of writing controllers and views. Unlike Spring MVC it is configured primarily through annotations which is something you will either love or hate.

On the topic of template engines it really boils down to identifying what exactly you do not like about jsp in the first place. Personally I find Java web development is hindered more by the controller frameworks than the templating language. Stripes is the best I have tried so far, but compared to Django and Rails it still feels a little cumbersome.

David Harrison
The question was about a templating framework, not a web framework, so I think the Stripes suggestion is irrelevant. Also, the comment that Spring MVC is not configured via annotations is out-of-date. Spring MVC can also be configured this way since 2.5.
Don
+1  A: 

Not exactly answering your question since it isn't a template engine, but you may want to look at Grails. It uses Spring MVC so the feel would be familiar. By default the views are Groovy Server Pages (.gsp) and I have found them very intuitive.

Ed.T
Grails uses Sitemesh.
Taylor Leese
A: 

It all goes down to what you need. For my current project, I am making an heavy use of FreeMarker because it was the framework that was tailored for the job I had to do. There is no silver bullets: You have to try them and choose one for yourself (And your team).

I've heard some nice reviews about Stripes from my colleagues who are actually doing some Web-Related Development.

Shadow_x99
+3  A: 

We have been using Sitemesh template engine in our spring web app and we are very happy with it. Reduces lot of maintenance work. An example of how to integrate with spring can be found in this blog

MM
+3  A: 

I would also like to add that your choice of template engine depends on the type of the output as well. If you know that your app will only have HTML output, I would suggest to stick with the standard JSP/JSTL. If your app requirement is also Excel, PDF or other format output, I would recommend Freemarker or Velocity. I personally like Freemarker better.

martinsb
I find that wanting HTML output is a good reason to avoid JSPs. They're a pain to write secure code in.
Dominic Mitchell
+8  A: 

I prefer Velocity to Freemarker for the clarity/simplicity of the syntax and professionalism of the community. I also get a lot of mileage out of the VelocityTools library. Freemarker can be a bit more intimidating but is also totally solid. It lacks VelocityTools, but makes up for it with native support for JSP tag libraries.

Either of these template languages is a great improvement over JSP/JSTL, if you ask me.

Nathan Bubna
Totally Agree! I avoid anything that supports JSP just so my devs can't try and use it. Velocity FTW
Pete
Disagree entirely. If you use the Spring Form tags, JSP development couldn't be easier.
MetroidFan2002
Velocity also has form tags (macroses) for Spring that make data binding for forms easier.
serg
+2  A: 

Try Spring Modules, which has support for web template engines like Freemarker, Groovy, Velocity, WebMacro and XSLT.

flicken
+3  A: 

I have not investigated using it with Spring yet, but I would not use any template engine but StringTemplate (see http://www.cs.usfca.edu/~parrt/papers/mvc.templates.pdf for why).

If you are set on Spring, then I would figure out how to integrate it with StringTemplate, although I suspect that it has already been done before.

Rob Williams
+2  A: 

If you like the Scala programming language you might like Scalate as it allows you to use powerful Scala expressions instead of the limited JSP/JSF/JSTL EL expression language - while being completely statically typed so that templates are checked at edit/compile time for errors.

The Scaml templates in Scalate let you write really DRY templates (Rails fans tend to love Haml and Scaml is the Scala port of Haml) - though if you're used to JSP you'd probably be better off starting with Ssp templates in Scalate which are JSP-like.

James Strachan
A: 

Hey, I have a problem because when i want to use this 4 technologies (SpringFramework, StringTemplate, JSTL, HIBERNATE) my JSTL do not work. But when i do not use ST - JSTL works. So I have a question is it possible integration this four technologies??

jolsys