-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi,
I am on ZK 8/8.5 and following https://www.zkoss.org/wiki/SmallTalks/2012/August/MVVMIn_Java for my project.
In the above example an invisible modal Window is build to show the confirmation dialog for deletion.
Here the relevant code snippets:
public void service(Page page) {
//1.Create root component which is to be associated with binder
Window window = new Window("Order Management", "normal", false);
window.setWidth("600px");
window.setPage(page);
//2. Instantiate a binder instance. Use DefaultBinder
binder = new DefaultBinder();
//3. Initialize it with View model and root component
binder.init(window, new OrderVM3());
//4. Set binder as an attribute on the root component
window.setAttribute("vm", binder.getViewModel());
[...]
buildConfirmDialog(binder, window);
// Must load value to components once, call it after all "add property binding" statements
binder.loadComponent(window,true);
}
If I modify the code to:
public void service(Page page) {
new OrderWindow().setPage(page);
}
where OrderWindow extends Window:
public OrderWindow() {
//1.Create root component which is to be associated with binder
super("Order Management", "normal", false);
setWidth("600px");
//2. Instantiate a binder instance. Use DefaultBinder
binder = new DefaultBinder();
//3. Initialize it with View model and root component
binder.init(this, new OrderVM3(), null);
//4. Set binder as an attribute on the root component
setAttribute("vm", binder.getViewModel());
[...]
buildConfirmDialog(binder, this);
// Must load value to components once, call it after all "add property binding" statements
binder.loadComponent(this,true);
}
I get:
Error 500 Cause: Not attached, <Window null>
I don't understand why the same code is not working when using the derived class. Do you? Thx
Hi,
without having executed your problems seems to be this:
Error 500 Cause: Not attached, <Window null>
--> which means that you are trying to do something to the component that requires it to be attached to the component tree (i.e. it has to happen after calling component.setPage(...)/setParent(...) or parent.appendChild(...) ...)
In your second case you are trying to initialize the binder inside the constructor. This will happen before setPage is called:
new OrderWindow().setPage(page);
to fix that you could split this into multiple calls (one constructor call and a separate method to initialize the binder/viewmodel and dependent components, that's roughly what ZK does internally too, first attach the component then init the binder/viewmodel, then create children, then load the bindings of the children)
OrderWindow orderWindow = new OrderWindow().setPage(page); //execute step 1.
orderWindow.myInitAfterAttach(); //execute steps 3-4
or pass the page
into the constructor so you can attach the component before calling binder.init
etc.
new OrderWindow(page);
I hope this makes sense... If not let me know
Asked: 2018-03-20 01:05:42 +0800
Seen: 8 times
Last updated: Mar 20 '18
zkspringmvc jar licence is GPL ?
Build web application without any zul files
Custom component that extends Textbox does not fire onChange event
java.lang.NullPointerException to update to zk 8.0.1
"Spring Session" + ZK + "Spring core" @Listen method refresh the screen
zk8 client side binding to a viewmodel command seems not to work
upload event dialog do not open in browser
Notification is not shown inside sticky block
Where can I find documentation (like ZK Developer's Reference) for ZK 8.0.2.2 ?