by Sibers CTO Andrey Gavrilov
From my point of view, the most powerful modern web framework is JBoss Seam since it utilizes the true power of JEE standards. However, Grails has two important advantages – it’s based on a dynamic language and it doesn’t require deep JEE knowledge to start working with.
However, once you start, you probably want more and one of the most desired directions is to move to Java Server Faces. Opponents of JSF claim that it uses JavaScript and thus isn’t usable for pure HTML. Well… it’s true – tag is transformed to form with JavaScript submit button (by the way, Seam has s tag to create non-Javascript links).
On the other hand, if you use AJAX it’s not a problem. More to say – JSF libraries (IceFaces and Tomahawk) are the best way to work with AJAX I’ve ever seen. So, first of all I’ve tried to combine Grails with JSF. The obvious way is the following:
•Add JSF handler servlet to web.xml template.
•Create custom variable resolver to allow accessing Grails helpers from JSF.
•Point to this variable resolver from within faces-config.xml OK, this should work, but it would completely ruin Grails logic since Grails controllers would not be used at all.
What we need is to add the following functionality:
•render should parse .xhtml and/or .jsf files as JSF,
•In JSF-generated files all links and forms should point to Grails controllers.
I dived into Grails sources and after a couple of hours emerged with assurance that before Grails plug-in system is released, it doesn’t make sense.
***
I tried to come from the other side – if I can’t bring JSF to Grails, probably I can bring Groovy to Seam? Working with two mature products is a pleasure. Just add groovy-all-1.0-RC-01.jar to your “lib” directory and add a couple of things to your build.xml:
<taskdef name="groovyc"
classname="org.codehaus.groovy.ant.Groovyc"
classpathref="build.classpath"/>
<target name="compile" depends="init"
description="Compile the Java source code"
unless="eclipse.running">
<groovyc
srcdir="${basedir}/gsrc"
destdir="${jar.dir}" />
<javac
classpathref="build.classpath"
destdir="${jar.dir}"
debug="${javac.debug}"
deprecation="${javac.deprecation}"
nowarn="on">
<src path="${src.java.dir}" />
</javac>
</target>
Now you may have your Groovy files in “gsrc” directory and they will be correctly compiled. Just one problem. One really BIG problem. Groovy doesn’t support annotations in its 1.0 version and so you can’t create Seam components (as well as any EJB3 or JPA entities) with it – just regular classes. Nothing to do but wait – annotation support is scheduled for Groovy 2.0.
Interesting entry. On the JSF+Groovy front, please see: http://blogs.sun.com/rlubke/entry/groovy_mojarra