-
FEATURED COMPONENTS
First time here? Check out the FAQ!
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; }
Thanks,
Chris
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
@Scope("request") @Controller @AppliedTo("myWindow") public class MyWindow { @Resource protected Window myWindow; }
Is this ZK stuff and/or Spring?
/Robert
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
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(){ ...
And some other things are not transparent for me - i.e. how the databinder could see the model.
/Robert
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
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
>> 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
Asked: 2009-04-15 07:49:24 +0800
Seen: 722 times
Last updated: Apr 17 '09