Re: Desired Features in FreeMarker
Daniel Dekany <[email protected]>
| Newsgroups | gmane.comp.web.freemarker.user |
|---|---|
| Message-ID | <[email protected]> |
Thursday, January 17, 2008, 7:32:14 PM, mraible wrote: > I've been doing quite a bit of prototyping with Spring MVC and Struts 2 with > both JSP and FreeMarker in the last few months. I'm trying to migrate a > proprietary servlet-based framework with a proprietary JSP compiler to > something that's open source. There's a couple of important features that > the proprietary view framework has: > > 1. It's expression language allows methods to be called with arguments. > 2. Templates can be loaded from a JAR on a remote server. > 3. XML in variables is escaped by default. > > For #1, I've found this to be impossible with JSP EL or JSTL. I've created > JSP functions that allow argument passing, but they don't allow overloading > of functions. FreeMarker solves #1. What do you exactly mean? I suppose both JSP EL and FreeMarker can call Java methods that are overload... but maybe I'm wrong? But I don't think FreeMarker supports the overloading "FreeMarker functions", i.e., the stuff that you define with <#functon>. > For #2, JSPs again fail because the templates have to be on the file system > or in a WAR. FreeMarker solves this problem as well. Yeah, that's a prominent weakness of JSP... it overtakes too much, without allowing you to optionally take control. > For #3, neither JSP or FreeMarker solve this problem. I realize it can be > fixed in FreeMarker by hacking the code - I've done the same with Tomcat and > solved it for JSP as well. That should be done by putting the whole template inside <#escape x as x?html>...</#escape>. I fully agree that it's silly... but by using the TempalteLoader you can insert this two tags automatically. > So based on the requirements in this project, FreeMarker is the clear > winner. However, there's a couple of questions I have. > > 1. When doing the JSP-based prototype with Struts 2, I was able to use JSP > 2.0 tag files to develop a <foo:body> tag that allows content to be added > around the body of the page. Does FreeMarker offer something similar, or is > it something like SiteMesh the only solution? You can define your own directives: http://freemarker.org/docs/dgui_misc_userdefdir.html But I'm not sure what you ask here... already written layout libraries maybe? In that case, you may can use an already existing JSP taglib, as with the correct setup, custom JSP tags can be used as FreeMarker directives. > 2. Is it possible to add static imports/methods to a context so > "url(foo).q(bar)" can be used instead of referring to the object that > contains the methods - "urlBuilder.url(foo).q(bar)"? Yes, methods can be top-level variables, because in FTL (FreeMarker Template Language) methods are first-class values. > 3. Is it possible to change how HTML is parsed so you can override or > customize the tag? The current compiler does this and it allows more > fine-grained control over template processing without requiring new macros > to be called. Like the automatic escaping, it's again a template pre-processing thing that can be done in TempalteLoader. (Once I have used it for automating forms.) However, FreeMarker has a shortage in supporting template preprocessing: it doesn't let the TempalteLoader to provide a position mapping, so preprocessing can result in the severe displacement of positions in the error messages. That is, the error messages will refer to the positions that are correct in the already preprocessed template, rather than in the template source file. So, I think we can count your requirement as +1 vote for adding position mapping. > Thanks for any information you can provide. > > Matt -- Best regards, Daniel Dekany ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/