1

mvvm detach [closed]

asked 2013-02-20 04:40:28 +0800

Col gravatar image Col
135 1 6

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?

delete flag offensive retag edit

The question has been closed for the following reason "the question is answered, right answer was accepted" by sjoshi
close date 2013-02-21 10:07:23

Comments

1

This is long time pending feature for ZK team

sjoshi ( 2013-02-20 04:43:57 +0800 )edit

Yes i agree with sjoshi.

Senthilchettyin ( 2013-02-20 05:26:48 +0800 )edit

4 Answers

Sort by ยป oldest newest most voted
2

answered 2013-02-20 09:58:21 +0800

hswain gravatar image hswain flag of India
1763 3 10
http://corejavaexample.bl...

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();
    }
}
link publish delete flag offensive edit

Comments

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

Thanks hswain. Works well. @Senthilchettyin: In the absence of a 'closing' annotation for MVVM it seems that any solution is going to couple the ViewModel with the View. Hopefully the ZK team can provide a fix soon.

Col ( 2013-02-20 22:57:17 +0800 )edit
2

answered 2013-02-20 05:54:43 +0800

sjoshi gravatar image sjoshi flag of India
3493 1 8
http://zkframeworkhint.bl...

I have created a Zk Issue tracker please add your vote so ZK team will take any action . Thanks

link publish delete flag offensive edit

Comments

1

Thanks for your input sjoshi. I have added my vote.

Col ( 2013-02-20 23:00:50 +0800 )edit
2

answered 2013-02-20 10:10:18 +0800

sjoshi gravatar image sjoshi flag of India
3493 1 8
http://zkframeworkhint.bl...

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();
    }
}
link publish delete flag offensive edit
0

answered 2013-02-20 05:46:29 +0800

rdgrimes gravatar image rdgrimes
735 7

updated 2013-02-20 05:48:11 +0800

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.

link publish delete flag offensive edit

Question tools

Follow
1 follower

RSS

Stats

Asked: 2013-02-20 04:40:28 +0800

Seen: 71 times

Last updated: Feb 20 '13

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