-
FEATURED COMPONENTS
First time here? Check out the FAQ!
I want to understand how the MVC pattern works with Spring + Hibernate, by analyze the code generated by Zeta Form Building.
Someone can tell me which annotation were used to do the relation between UI (.zul file) and the Controller, and how it work?
Thanks in advance ...
thanks robertpic71 for your reply.
In waiting the specs, I tried to imitate the code of Zeta Form Building, but It didn't work ( but it worked with <window apply=""> instead of @Controller and @AppliedTo)
My example, it will change the value of label when we click on the button
index.zul
<zk> <window id="personWin" title="Home Page" border="normal" width="50%"> <label id="lbTest" value="Test"/> <separator></separator> <button id="btnTest" label="Click here ..."/> </window> </zk>
IndexController.java
import ... @Scope("idspace") @Controller @AppliedTo("personWin") public abstract class PersonController { @Resource protected Window personWin; @Resource protected Label lbTest; @Resource protected Button btnTest; // ZK DataBinder protected DataBinder binder; public PersonController(){} @AfterCompose public void afterCompose() { binder = new AnnotateDataBinder(personWin); personWin.setVariable("personWinBinder", binder, true); binder.loadAll(); } @EventHandler("btnTest.onClick") public void doCancel(Event event) { lbTest.setValue("This line was changed ..."); }
Someone can tell me where is the error??
Thanks
The simplist way should be: execute one project with zeta, for the correct Spring-config.
Maybe you need to include your packages or the zk packages for annotations:
mainly the following two lines and of course some XML name space definitions about zksp-annot and zksp.
<!-- ZK Spring config -->
<zksp-annot:component-scan base-package="org.zkoss.spring.jpa,org.zkforge.todo" />
<zksp:zk-config />
org.zkoss.spring.jpa includes the zk-spring-annos.
org.zkforge.todo --> should be your root package (including the controller)
BTW: The zeta-code is really nice - paging and sorting is done via database.
/Robert
Hi Robert, it didn't work out :( --> sad
My steps:
- Create one ZK project from Zeta Form Builder (Project1)
- Create another project Web (from 0) --> Project2
- Copy all .jar file from Project1\WebContent\WEB-INF\lib\ to Project2\WebContent\WEB-INF\lib\
- Copy Project1\src\config to Project2\src\config (modify a little bit as you said for Spring's config)
- Copy Project1\WebContent\WEB-INF\web.xml to Project2\WebContent\WEB-INF\web.xml
Like that, I think all configurations are the same as Zeta code
From that, I implemented index.zul and IndexController.java above, but it didn't work.
If you have a piece of correct code which used @Controller and @AppliedTo, please send it to me, thanks
Here a minimal example:
[and once more: SPECS ARE NOT FINAL]
index.zul
<?page title="Index" contentType="text/html;charset=UTF-8"?> <zk> <window id="indexWin" title="Index" border="normal"> <label id="hide" /> <button id="show" label="Show" /> </window> </zk>
IndexController.java
package com.at.od.controller; import javax.annotation.Resource; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Controller; import org.zkoss.spring.context.annotation.AfterCompose; import org.zkoss.spring.context.annotation.AppliedTo; import org.zkoss.spring.context.annotation.EventHandler; import org.zkoss.zul.Label; @Scope("idspace") @Controller @AppliedTo("indexWin") public class IndexController { @Resource protected Label hide; @AfterCompose public void afterCompose() { hide.setValue("Start"); } @EventHandler("show.onClick") public void doView() { hide.setValue("Clicked!"); } }
application-context.xml
<zksp-annot:component-scan base-package="org.zkoss.spring.jpa,webtests,com.at.od.controller"/>
<zksp:zk-config/>
Add your package. Check Spring-docs for more (generic) options.
Do you use the zk professional package? (other parts of zeta, don't work with standard-package - i'm not sure about spring).
/Robert
1.) What version of ZK you are using?
2.)
a.) This could be a missing zk namepace inside the application-context.xml. (let zeta create the spring config and create at least one form)
b.) Maybe the annotation don't work anymore or the syntax have changed - because the specs was not final.
3.) If I have some time, i'll try to check this with a new version. I've only tested this features and not used in productive envirnoment (cause unfinished specs).
@ZKTeam
4.) Any news about an official launch?
/Robert
Robert,
Thanks for to reply!
I'm using the ZK 5, and I tried with version CE and PE and it didn't work!
I try create a simple project with ZK Studio Project, putting the spring jar's and make the configuration of file "applicationContext.xml" with the tag <zksp:zk-config/> and nothing! Error! :(
The configuration of my project is Spring 3 + JPA 2.0 + Hibernate 3, and only this function isn't work!
I used some features of ZK 5 and because of it, I can't make the downgrade! I will continue find the solution or wait for a new version for zkspring.jar integration that resolves it.
Are you using the version EE in your project ? If you have access could you try with this version!
/Thanks
/Danilo
Hi Danilo
Did you download the latest zkspring ?
Asked: 2009-04-20 10:00:51 +0800
Seen: 2,385 times
Last updated: Nov 04 '10