Implementing Tapestry Component Methods with Groovy (Part II)
Richard Hensley was also working on
integrating Groovy with Tapestry. He took my groovy-listener code and
incorporated it with his own code. We created a project on sourceforge and as
christened by Howard we called the project,
Groovestry.The combined codebase is
documented at: http://groovestry.sf.net and the source code can be
downloaded from http://www.sf.net/projects/groovestry.The
class and package names may have been changed but Groovestry still supports the
feature set described in my earlier
postin
g, with the addition of several features from Richard's original
implementation. These
include:Declaration of scripts as
component or page beans:
<bean name="miscMethods"
lifecycle="page"
class="org.apache.tapestry.contrib.script.ScriptBean">
<set-property name="script">
'MiscMethods'
</set-property>
</bean>
Which looks for a file MiscMethods.groovy in
the same location as the component or page
specification.Methods in these bean-declared
scripts can also be bound to listeners in the
page:
<à href="Page2.html"
jwcid="@DirectLink"
listener="ognl:beans.miscMethods.beanTestMethod">Click here</a>
This allows multiple scripts to be used by a
page and the same script may be referenced on multiple
pages.Groovy scripts no longer have to
be formal classes, the 'def' keyword can be used to define functions in the
scriptwhich can be bound as listeners in
the page or component. Listener method definitions may declare between 1 and 3
arguments withthe following method
signatures:
def listener1(cycle) {
}
/*
* This listener is called with the page and the request cycle.
*/
def listener2(page, cycle) {
}
/*
* This listener is called with the page, component, and
* the request cycle.
*/
def listener3(page, component, cycle) {
}
Scripted classes, particularly those with the
same name as the Component or Page behave as I documented earlier and can still
be compiled to .class files for deployment if they are added to the package
<namespace>.script
where namespace is the namespace the component is
deployed from, application scripts can be compiled if they are declared with
package
application.scriptThe
example application has been updated to use the new code, and the source code
tree has been modified so that the script-enabling code can be built and
deployed as a jar which is used by the sample
application.Thanks to Richard for
doing all of the work to integrate the two sets of source code and integrate the
test cases.
Posted: Thu - August 5, 2004 at 08:16 AM
|