0

Zeta Form Builder - interaction between UI and Controller ?

asked 2009-04-20 10:00:51 +0800

TLHP gravatar image TLHP
111 1 3

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 ...

delete flag offensive retag edit

24 Replies

Sort by ยป oldest newest

answered 2009-04-20 14:58:01 +0800

robertpic71 gravatar image robertpic71
1275 1

updated 2009-04-20 14:58:25 +0800

The specs are "under construction" - check henri's comment.

/Robert

link publish delete flag offensive edit

answered 2009-04-20 15:31:47 +0800

TLHP gravatar image TLHP
111 1 3

updated 2009-04-20 15:35:55 +0800

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

link publish delete flag offensive edit

answered 2009-04-20 16:51:20 +0800

robertpic71 gravatar image robertpic71
1275 1

updated 2009-04-20 16:58:16 +0800

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

link publish delete flag offensive edit

answered 2009-04-21 09:37:29 +0800

TLHP gravatar image TLHP
111 1 3

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

link publish delete flag offensive edit

answered 2009-04-21 10:29:49 +0800

robertpic71 gravatar image robertpic71
1275 1

updated 2009-04-21 13:55:07 +0800

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

link publish delete flag offensive edit

answered 2009-04-21 15:57:56 +0800

TLHP gravatar image TLHP
111 1 3

It worked :), thanks Robert

link publish delete flag offensive edit

answered 2010-08-26 11:19:56 +0800

dandrop gravatar image dandrop
39

Robert,

I'm try a example and only appear this bug!

cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'zksp-annot:component-scan'.

How can i solve this ?

link publish delete flag offensive edit

answered 2010-08-26 12:29:14 +0800

robertpic71 gravatar image robertpic71
1275 1

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

link publish delete flag offensive edit

answered 2010-08-27 15:32:55 +0800

dandrop gravatar image dandrop
39

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

link publish delete flag offensive edit

answered 2010-08-30 20:12:57 +0800

jimmyshiau gravatar image jimmyshiau
4921 5
http://www.zkoss.org/ ZK Team

Hi Danilo
Did you download the latest zkspring ?

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2009-04-20 10:00:51 +0800

Seen: 2,385 times

Last updated: Nov 04 '10

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More