XpdWiki

FrontPage
RecentChanges
XtC
FindPage
PageIndex
XpApprentices

Set your name in
UserPreferences

Edit this page

Referenced by
JavaServerPages




JSPWiki v2.0.52


JspAlternatives


Now I've used JakartaVelocity to generate Java source and its a short hop to generating HTML. VTL is very simple to read and use and to my mind keeps the mark-up and the dynamic stuff well separated which is nice. The ease of using (sometimes psuedo)Java in either (especially JSP) is quite worrying since the view can more easily end up knowing all sorts of stuff that it shouldn't, and why bother with it in the view when your servlet can do all the grunt work in plain old Java.

I always apply the mantra "how will I test that the stuff we write works?" these days to any new technology. Apply this to JSP - I need to deploy a web-application into a web-server to test a simple piece of HTML is generated? That just doesn't sound very quick to do, that deployment cycle is going to take half a minute every time and I can't easily get at the code I want to test.

It's dependent on using Java code generation technology that's in the container so to even start to fix any problems I have to let the JSP run and fail and then take the code that's been generated and look in that to see where the problem is. So I can't really ever test the code I have written since I don't write any directly!

Then I looked at Velocity and servlets. I don't really need a container - If the view generation classes can plug into a generic servlet then since I'm not testing the servlet and just the generation logic I can just call the view classes directly. I simply write my templates run my Java program and see what HTML is generated there and then. Nice.

Then I looked at Joe's Walnes Jelly and his 3 stage path from JSP to Velocity to Jelly. His one problem with Velocity is what I call its anti-duplication expressions. Basically if you find yourself writing the same snippet of mark-up again and again you can use a simple tag in JSP to define that mark-up and then use the simple tag every where instead. There is the concept of a Velocity macro however Joe was less impressed with it for reasons unknown...

I had a look at Maven and its use of Jelly and its looks like it could be the best of both worlds, but its a little bleeding edge for our application.

So then I bought the book "XP for web projects" over Christmas here's way they say in XpForWebProjects


You've done a lot of exploring, which is cool. You've almost certainly learned something you needed to know. Now for a question that will put this learning to use : what is, for you, the simplest thing that could possibly work ?³rev³2³JspAlternative ³³date³December 31, 2002³host³³agent³Mozilla/4.0 (compatible; MSIE 5.01; Windows 98)³JspAlternatives


I keep stumbling across oblique references to using Velocity to generate java source, but for some reason I can't seem to find any basic tutorials on how to use Velocity to do this. I guess I'll just have to read up on using it to produce HTML, and figure it out from there.

StevenJOwens?


Er, why would you ever need to use GeneratedCode?? Surely you can solve the percieved problem using YetAnotherLevelOfAbstraction?. If you're actually trying to overcome limitations of the Java language (e.g. StrongTyping?, or PoorMansCollections? then you might want to consider using one of the many other languages that execute on the JavaVM? like JPython, JavaScript (via Rhino) -- OliverBye
My primary reason for using GeneratedCode? is that the rest of the Java world uses techniques that involve lots of what I call monkey-code (something a trained monkey could do, for example javabean getters/setters). I have to write code that works with the rest of the world, so I spend a lot of time generating monkey code. I'd rather generate it automatically, avoid stupid typos, and spend more of my time on the code that really matters.

StevenJOwens?


A python-based alternative to Velocity that I have been using recently is CheetahTemplates? (http://cheetahtemplate.org/). This has a template syntax similar to Velocity, but compiles the template into a Python class, which can be used to generate the text at runtime. This means that you have the full power of inheritance and polymorphism at your disposal. You can derive templates from other templates or from Python classes, and derive Python classes from your template. This gives a power and flexibility almost on a par with Zope's acquisition, but without all the baggage. -- DaveKirby



Edit this page   More info...   Attach file...
This page last changed on 09-Dec-2003 03:44:36 GMT by unknown.