5

I'm working on a web applications that uses Struts 1.1 and tiles with jsps. I'd like to introduce some freemarker templates.

I know this is possible with Struts 2, but can you use freemarker with Struts 1?

Snukker
  • 1,963
  • 3
  • 18
  • 18
  • `Freemarker` has some nasty dependencies, and doesn't promote pure separation of content and logic which will cause headaches down the road in maintenance. `StringTemplate` is a much better template library from a design and implementation stand point. –  Apr 27 '11 at 15:11
  • 2
    @Jarrod Roberson FreeMarker has no mandatory dependencies. As for the separation of content and logic, I don't see how StringTemplate - or any other template engine - is any more "pure". – Laurent Pireyn Apr 27 '11 at 15:27
  • Just because you don't understand something doesn't make it wrong, it just means you don't have complete information. If you read the [first paragraph](http://www.stringtemplate.org/) on the StringTemplate home page you would understand why Freemarker and its ilk are sub-optimial. With StringTemplate, **"Its distinguishing characteristic is that it strictly enforces model-view separation unlike other engines. Strict separation makes websites and code generators more flexible and maintainable; it also provides an excellent defense against malicious template authors."** –  Apr 27 '11 at 15:45
  • Here is the [dependency list](https://freemarker.svn.sourceforge.net/svnroot/freemarker/trunk/freemarker/ivy.xml), and it depends on the AWT Tree class as well, which takes using a hacked version to work on Google App Engine. Nasty dependency for non-visual code to be relying on AWT classes. –  Apr 27 '11 at 15:52
  • Perhaps I should rephrase my question as "How can I use a templating engine other than jsps with Struts 1" – Snukker Apr 27 '11 at 16:22
  • 1
    @Jarrod Roberson As I wrote, FreeMarker has no *mandatory* dependencies. It *can* use several other libraries, but they are *optional*. – Laurent Pireyn Apr 27 '11 at 21:58
  • 1
    @Jarrod Roberson Just because Terence Parr wrote something about his template engine doesn't make it the be all and end all of template engines. StringTemplate is based on a very strict separation between the model and the view, but such a separation has a price: the model must be carefully designed for that purpose, and the lack of control in the templates can be very difficult, especially for beginners. I've tried both and I've found FreeMarker to be easier to use and more productive. – Laurent Pireyn Apr 27 '11 at 22:09
  • 1
    @Jarrod: You're actually citing a dependency list for the Freemarker-Ivy integration, not for Freemarker itself. The Freemarker-Ivy list is a real mess, and even includes Jython, JRuby, and Rhino! Freemarker works fine without all that crud. I think Terence's "other engines" is a reference to JSP, ASP, and PHP templating. – Jim Ferrans Apr 27 '11 at 22:25
  • Freemarker still depends on AWT classes which is ridiculous for a non-visual library. And beginners should learn to do templating correctly, which is no logic in the template. Every other templating solution regardless of language, and I am not talking about JSP, ASP or PHP, gets this wrong. If you can put logic in your template, you can introduce heinous problems when your model code changes and the order of execution changes and data is no longer available when the template logic thinks it is. If you want to trace down those errors, and I have had to with Freemarker, as well as Velocity. –  Apr 28 '11 at 04:48
  • Fine but I would rather have a template solution that doesn't put a loaded gun in the hands of a developer that puts a bunch of logic in the templates and shoots themselves, and the team in the head when changes to the code part occur. –  Apr 28 '11 at 04:49
  • 1
    @Jarrod: Here's the link you should cite about the AWT/Swing dependency: http://freemarker.sourceforge.net/docs/api/freemarker/core/FreeMarkerTree.html That *is* pretty peculiar. Wow! – Jim Ferrans Apr 28 '11 at 06:06
  • @Jim Ferrans: Thanks, for the link I will cite it in the future. –  Apr 28 '11 at 06:08
  • @AntiStringTemplate folks, http://www.digitalsanctum.com/2006/04/05/stringtemplate-vs-velocity-vs-freemarker/ –  Apr 28 '11 at 06:08
  • @Jarrod: FreeMarker allows you to call arbitrary methods on the model object (http://freemarker.org/docs/dgui_template_exp.html#dgui_template_exp_methodcall). So Terence's concerns about model-view separation do apply to undisciplined use of Freemarker as well as to the more obvious examples I cited above. Terence explains this in http://www.cs.usfca.edu/~parrt/papers/mvc.templates.pdf. – Jim Ferrans Apr 28 '11 at 06:25
  • I'll take a look at StringTemplate while evaluating Freemarker and see what I think. – Snukker Apr 28 '11 at 11:03

1 Answers1

3

Freemarker is usable with Struts 1.1. Here's a story on Freemarker 2.2 from back in March 2003. One of the commenters tells how to integrate Freemarker 2.2 with Struts. That has to be Struts 1 since Struts 2 doesn't appear until March 2006 (here's v1 of the first release notes of Struts 2).

Jim Ferrans
  • 30,582
  • 12
  • 56
  • 83
  • Thanks, according to http://freemarker.org/docs/pgui_misc_servlet.html, Freemarker comes with a ready-made Servlet that you can configure in web.xml. I imagine this will do the job exactly as I require. – Snukker Apr 28 '11 at 11:02