ZK plugin for Grails
flyisland · ) · 2007-10-31
2007-10-31 14:23
ZK plugin for Grails
-
[
开发
]
Tag:
ZK
Grails
(update 20071102: I have just released the 0.2 version of ZK plugin, which allows Grails
controllers and ZK work together now, you can download the new version
on (http://docs.codehaus.org/display/GRAILS/ZK+Plugin ).)
Grails
: agile, industrial strength, rapid web application development made easy!
ZK
: the simplest
way to make Web applications rich!
Do you want to combine both of them?
1. Install & test the ZK plug-in
1) Install Grails first (
http://grails.codehaus.org/Installation
)
2) Follow the Grails Quikc Start (
http://grails.codehaus.org/Quick+Start
),
to build a simple Grails project with the Book domain class
3) Download ZK plugin (
http://flyisland.blogbus.com/files/11938117910.zip
),
and rename the file to "
grails-zkplugin-0.1.zip
", make sure you are in the root directory of your project, type
grails install-plugin full_path_to_zk_plugin
4) create a new file "list.zul" under
"your_project\web-app" with the following content
--------------------------list.zul-------------------------------
<?xml
version="1.0" encoding="UTF-8"?>
<?page
zscriptLanguage="Groovy"?>
<window border="normal" title="Groovy Test" id="MainWindow" width="400px">
<zscript>
books = Book.findAll()
</zscript>
<listbox>
<listhead>
<listheader label="ID"/>
<listheader label="Title"/>
<listheader label="Author"/>
</listhead>
<listitem forEach="${books}">
<listcell label="${each.id}"/>
<listcell label="${each.title}"/>
<listcell label="${each.author}"/>
</listitem>
</listbox>
</window>
-----------------------------------------------------------------
5) test "list.zul", make sure you are in the root
directory of your project, type "grails run-app", then browse
to "
http://localhost:8080/your_project/list.zul
",
you should be able to view the following list.
2. How does ZK plugin do it?
Actually, you can find the whole source code of this plugin
by browsing to "your_project\plugins\zkplugin-0.1", right now,
ZK plugin is made up of three parts.
1) maintaining the basic ZK realted java libaries
2) Participating in web.xml Generation to add ZK related
servlets
3) Participating in web.xml Generation to modify the
"url-pattern" of Grails filter "sitemesh"
I find that accessing the "zul" file will just
return a blank page with "sitemesh" filter mapped to
"/*", so I have to modify the "url-pattern" of
Grails filter "sitemesh". It means that you can
NOT
use Grails controller after you installed
the ZK plugin!
I'm still working on it to see if there is a way to let
Grails filter "sitemesh" to ignore some particular
url-patterns, your comments are welcome!
3. Accessing the domain class
As you can see in the above sample, accessing domain classes
in ZK is very simple, just as what you can do in Grails controller.
4. Accessing the service
Accessing grails services in ZK is also very easy. Grails
will define a bean with name "xxxService" of each service
"XxxService", and you can access the Services in zscript
directly with the help of
DelegatingVariableResolver
.
1) create a service.
create a new file "HelloService.groovy" under
"your_project\grails-app\services" with the following content
-------------------HelloService.groovy-----------------------
class HelloService {
boolean transactional = true
def serviceMethod(username) {
return username+", welcome to ZK&Grails world!"
}
}
-----------------------------------------------------------------
2) create a zul file
create a new file "service.zul" under
"your_project\web-app" with the following content
-------------------------service.zul---------------------------
<?xml version="1.0" encoding="UTF-8"?>
<?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?>
<?page zscriptLanguage="Groovy"?>
<window border="normal" title="Groovy Test" id="MainWindow" width="400px">
<textbox id="username"/>
<button label="Call HelloService"
onClick="result.value=helloService.serviceMethod(username.value)"/>
<separator/>
<label id="result"/>
</window>
-----------------------------------------------------------------
3) test it
Browse to "http://localhost:8080/your_project/service.zul", input a name and click the button!
Enjoy it, and any comments is welcome!
flyisland
@ 14:23 |
引用 0
|
编辑
评论
Nice work! Therer's a way to tell sitemesh to exclude some URLs, usually in the decorators.xml file.
flyisland 回复 Pablo 说:
thanks Pablo, I'll try it to see how to exclude some URLs
(2007-10-31 23:21:50)
Pablo
(
回复
]
Oh , my god ... I try to understand it ,but in vain
flyisland 回复 小单 说:
xixi, I'm not surprised about that :)
(2007-10-31 17:23:50)
小单
(
回复
]
发表评论
姓名:
E-mail:
地址:
原始快照:web.archive.org