0

ZK-Spring Annotations - Controller bound to old Instance...

asked 2009-04-15 07:49:24 +0800

christian gravatar image christian
136 2 4

Hi Guy's,

i'm currently using the new ZK-Spring (1.2 SVN) to make a new application.

Now i hit a problem:

My app is opening dialogs for user input. This Dialogs are windows. Nothing special so far...

The windows are opened via:

Window win = (Window)Executions.getCurrent().createComponents("window.zul" , null, args);
win.doHighlighted();

This window has a controller registered via spring and zk-spring annotations.
It works - for the first time. If i close and reopen the window, its not working any more.
I traced it down and it seems that all the components bound to the controller are from the first window, not from the current one.

What did a wrong?

For the controller i'm using:

@Scope("request")
@Controller @AppliedTo("myWindow")
public class MyWindow {

	@Resource
	protected Window	myWindow;	

}

i also tried @Scope("idspace");

Thanks,
Chris

delete flag offensive retag edit

11 Replies

Sort by ยป oldest newest

answered 2009-04-15 08:18:28 +0800

christian gravatar image christian
136 2 4

Hi again,

i digged a bit, and the problem is:

The creation of the new Window is started by pressing a button. So "self" is the button.
Now the trouble begins: The idspace for the new window is not the new window itself, its the window where the button is placed.
And for each component resolved, a ZkComponentFactoryBean is created. But this bean is linked and keeps linked to the initial window, even if it's gone in the meantime...

Is it a bug?

Bye,
chris

link publish delete flag offensive edit

answered 2009-04-15 08:30:28 +0800

henrichen gravatar image henrichen
3869 2
ZK Team

Chris,

Yes. It is a bug. Would you help post this to ZK Bugs. Thanks.

link publish delete flag offensive edit

answered 2009-04-15 09:17:57 +0800

christian gravatar image christian
136 2 4

Hi Henri,

bug created: https://sourceforge.net/tracker/?func=detail&aid=2764814&group_id=152762&atid=785191

thanks,
chris

link publish delete flag offensive edit

answered 2009-04-15 15:00:35 +0800

robertpic71 gravatar image robertpic71
1275 1

updated 2009-04-15 15:01:39 +0800

@Scope("request")
@Controller @AppliedTo("myWindow")
public class MyWindow {

	@Resource
	protected Window	myWindow;	

}

Are there any docs, about the @AppliedTo and @Resource for ZK components? (I've also started a documentrequest last week..)

Is this ZK stuff and/or Spring?

/Robert

link publish delete flag offensive edit

answered 2009-04-16 07:33:15 +0800

christian gravatar image christian
136 2 4

Hi Robert,

as far as i traced it down:
AppliedTo() is a ZK "extension" to link a Controller to the dialog. It seems that during component generation something is looking for the controllers and linking the dialog with it. Haven't chased that mechanism yet.

@Resource is working via the Spring Bean namespace, in combination with the @Scope namespace scope. A few facts:
ZK registers an own spring scope: org.zkoss.spring.web.context.request.IdSpaceScope
This scopes searches through the ZK pages and has some anchors (like Window or Panel, indeed each ZK component implementing the IdSpace interface) where namespace extensions are stored into. Each time a Spring Bean is requested and not found in the global namespace, the IdSpaceScope is hit and tries to find a ZK component matching this bean. If one is found, this "ZK Componet Bean" is bound to the controller. The @Scope() just tells which searcher should be used (IdSpaceScope, PageScope, DesktopScope, ...)

There are some more annotations:

@AfterCompose
public void afterCompose() {
}

Its the already known afterCompose handler. In days of annotation you don't have to implement additional interfaces like in former days, your afterCompose() method is triggered by the @AfterCompose annotations.

@EventHandler("myButton.onClick")
public void onClickHandler() {
}

@EventHandler("myList.onSelect")
public void onSelctHandler(Event event) {
}

That's the way to link events with methods. Just like explained in http://docs.zkoss.org/wiki/ZK_MVC_Made_Easy transfered to annotations ;)

I stumbled over this analyzing a quick sample done with the zeta wizard, and adopted it for my application. Maybe you also do a simple zeta demo and have a close look to the code ;)

bye,
chris

link publish delete flag offensive edit

answered 2009-04-16 09:10:21 +0800

robertpic71 gravatar image robertpic71
1275 1

Thanks, i also see this annotations in the zeta-code. I started a documentation-request last week - but no answer until now..

I've tried some improvments for the zeta-templates and searched for background-information.

i.e. try multiple events:

@EventHandler("beanSearch.onOK")                 // do not work, accept only one @EventHandler
@EventHandler("personnelQuery.onClick")
   public void doFilter(){
...

Fulltextsearch should fired by the button or the enter-key within the searchfield.

And some other things are not transparent for me - i.e. how the databinder could see the model.

/Robert

link publish delete flag offensive edit

answered 2009-04-16 12:06:26 +0800

christian gravatar image christian
136 2 4

hi,

that's quite an 'annotation bug collecting' thread here ;)

i've just hit another bug:

Window parentWin = new Window();
Window win = (Window)Executions.getCurrent().createComponents("window.zul" , parentWin, args);
win.doHighlighted();

and your controller won't be bound - namespace issue...

Yes, there are many "unclear" things...

ie, for the fulltextsearch you could do something like this:

@EventHandler("searchTextfield.onKeyDown") // not sure if KeyDown is the right event...
public void doCtrlKey(Event event) {
	final int keycode = ((KeyEvent) event).getKeyCode();
	if (keycode == KeyEvent.DOWN || keycode == KeyEvent.UP){
           // look for CR and fire search
        }
}

to the point with databinder and model: do you mean this line:

binder.loadAttribute(articleDataListView, "model"); //reload model to force refresh

that's because of this in the zul file:

<listbox id="articleDataListView" multiple="false" model="@{articleModel.all}"
selectedItem="@{articleModel.selected}" style="border:none">

The listbox with the ID articleDataListView has model bound via databinder...

Bye,
chris

link publish delete flag offensive edit

answered 2009-04-16 12:23:52 +0800

christian gravatar image christian
136 2 4

Hi Again,

found the "problem" with my controller not bound situation:

The Controller is found via the page (page resolves over Spring Beans).

the problem is solved if the window, where the new component is created into, is attached to the desktop before calling createComponents(). No idea if this is intended or a bug...

Window parentWin = new Window();

parentWin.setParent(myParentComponent); // this is the magic..

Window win = (Window)Executions.getCurrent().createComponents("window.zul" , parentWin, args);

bye,
chris

link publish delete flag offensive edit

answered 2009-04-16 12:32:49 +0800

robertpic71 gravatar image robertpic71
1275 1

>> to the point with databinder and model: do you mean this line:
>> binder.loadAttribute(articleDataListView, "model"); //reload model to force refresh
Oh thanks, i missed this line...

To handle the enter-key i changed:
@EventHandler("personnelQuery.onClick") --> @EventHandler("personnelQuery.onClick,beanSearch.onOK")

Now the search can be fired by the button or the enter-key (inside the search textbox)

@EventHandler("personnelQuery.onClick,beanSearch.onOK")
public void doFilter(){
   if (Strings.isBlank(_filter)) {
	personnelModel.setWhere(null);
	personnelModel.setParameters(null);
   } else {
	//TODO:shall process filter string into JPQL where statement here
	prepareQueryConditions();
   }
   refreshModel();
}

/Robert

link publish delete flag offensive edit

answered 2009-04-17 08:33:34 +0800

christian gravatar image christian
136 2 4

Hi Robert,

thanks for this info ;)

this hint could solve some people's asking how to bind more then one event source to an annotated EventHandler (try to drop some buzzwords for the search ;) ).

Bye,
chris

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-15 07:49:24 +0800

Seen: 722 times

Last updated: Apr 17 '09

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