But you are tight coupling. The whole concept of MVVM is it should not tightly coupled with UI. Instead of this we can use genericcomposer or selectcomposer
Senthilchettyin ( 2013-02-20 12:42:34 +0800 )edit-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Am I missing something when it comes to MVVM and closing windows? The reason for MVVM is "separation of data and logic from presentation". However this doesn't seem possible when it comes to closing a window. The only solutions I found while looking into this problem says to @Wire the window into the ViewModel. However the premise behind MVVM is to avoid doing just that.
If there is indeed no way to detach a window without having to wire it into the ViewModel (it's expected that users will manually close all windows?) would it not be possible to create a @destroy (or similar) annotation?
try this code
import org.zkoss.bind.annotation.AfterCompose;
import org.zkoss.bind.annotation.Command;
import org.zkoss.bind.annotation.ContextParam;
import org.zkoss.bind.annotation.ContextType;
import org.zkoss.zk.ui.Component;
public class DemoTest {
/**
* @author Himanshu
*/
Component parent;
@AfterCompose
public void afterCompose(@ContextParam(ContextType.VIEW) Component view) {
this.parent = view;
}
@Command
public void detachWindow() {
this.parent.detach();
}
}
But you are tight coupling. The whole concept of MVVM is it should not tightly coupled with UI. Instead of this we can use genericcomposer or selectcomposer
Senthilchettyin ( 2013-02-20 12:42:34 +0800 )editI have created a Zk Issue tracker please add your vote so ZK team will take any action . Thanks
Ok @hswain we can do this thing....
public class DemoTest {
/**
* @author Himanshu
*/
@AfterCompose
public void afterCompose(@ContextParam(ContextType.VIEW) Component view) {
}
@Command
public void detachWindow(@ContextParam(ContextType.VIEW) Component view) {
view.detach();
}
}
Just an idea. You could create a session (or other scope) attribute that contains a list of created windows. Whenever a window is created, have it's viewmodel or controller simply add its corresponding window to the list. Depending on your criteria for what triggers the closing of all open windows, you could publish something like a "closeWindows" to an event queue. Your ViewModel, or actually any other instantiated class you choose, could subscribe to that event queue. When it receives the pushed event, it could retrieve the list of open windows from the session attribute, loop through them, performing a detach on each window.
Seems like a lot of work, but actually requires little code to achieve, while retaining the ViewModel's ignorance of any attached view.
Asked: 2013-02-20 04:40:28 +0800
Seen: 71 times
Last updated: Feb 20 '13
Databinding and auto-complete on combobox
Composite component and bind in ZK 6
How to detach / reattach MVVM windows?
Is there a way to resolve view model properties as input to client side javascripts?
How can I synchronize data in a ListBox in MVVM ? [closed]
MVVM Validator: class not found ? [closed]
How to Call Child ViewModel Method from Parent Window? [closed]
This is long time pending feature for ZK team
sjoshi ( 2013-02-20 04:43:57 +0800 )editYes i agree with sjoshi.
Senthilchettyin ( 2013-02-20 05:26:48 +0800 )edit