0

No invisible modal window in class deriving Window [closed]

asked 2018-03-20 01:05:42 +0800

exactt gravatar image exactt
50 2

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

delete flag offensive retag edit

The question has been closed for the following reason "the question is answered, right answer was accepted" by cor3000
close date 2018-03-21 15:04:08

1 Answer

Sort by ยป oldest newest most voted
1

answered 2018-03-20 12:03:38 +0800

cor3000 gravatar image cor3000
4406 2 7
ZK Team

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

link publish delete flag offensive edit

Comments

Thx a lot! That was exactly my problem. You made my day.

exactt ( 2018-03-21 06:08:01 +0800 )edit

you're welcome

cor3000 ( 2018-03-21 17:32:17 +0800 )edit

Question tools

Follow
1 follower

RSS

Stats

Asked: 2018-03-20 01:05:42 +0800

Seen: 8 times

Last updated: Mar 20 '18

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