0

How clode modal window from class [closed]

asked 2013-01-18 20:54:43 +0800

Eustas gravatar image Eustas
75 1

I use mvvm approach.
I have such method in zul page

<button label="add" onClick="@command('toPeopleChoose')"/>

My mvvm class

  @Command
  @NotifyChange("*")
    public void toPeopleChoose()
    {
        Window modalWindow = (Window) Executions.createComponents("page1.zul", null, null);
        modalWindow.doModal();
    }

where page1.zul is page that should be opened in the new modal window.

I invoke such method on next step for page1.zul also. This next page located in front of page1.zul.
So when I click "Cancel" at page2.zul with such code

<window id=page2 ....
<button label="Cancel" onClick="page2 .detach();"/>

page2 is closed and I see again page1.

But how can I save link to current modal window in my mvvm class? And how can I close modal window from mvvm class?

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-08 07:23:28

6 Answers

Sort by ยป oldest newest most voted
2

answered 2013-01-21 06:53:54 +0800

psingh gravatar image psingh flag of India
963 8

We have 2 ways to close the modal window.
1- Taking property and set visiblity of page to false & true.
In zul file

<groupbox  mold="3d" height="70%" visible="@load(vm.showDialog)"
		 ></groupbox>

In class,

public class MyViewModel {
private boolean showDialog = true; // to show the dialog
public void getShowDialog();
public void setShowDialog(boolean showDialog);

@NotifyChange("showDialog ")
public void cancel()
{
showDialog = false; // to close the modal window
}
}

2- Wiring the window id in java class and use detach() method to close it.
Eg.
In zul file

<groupbox mold="3d" height="70%"
		id="grpID"></groupbox>

In java class,

public class MyViewModel {
@Wire
Groupbox grpID;

public void cancel()
{
    grpID.detach();  // to close the window
}
}

link publish delete flag offensive edit
0

answered 2013-01-21 02:05:39 +0800

samchuang gravatar image samchuang
4084 4

@Eustas

"addPeopleToList", it looks like a command, is't ?

refer to Communication between ViewModel and Composer

when invoke "addPeopleToList", you can "Posting a Command from a ViewModel to a Composer", then the composer will close the window

link publish delete flag offensive edit
0

answered 2013-01-20 04:27:37 +0800

Senthilchettyin gravatar image Senthilchettyin flag of India
2623 3 8
http://emrpms.blogspot.in...

Check here

link publish delete flag offensive edit
0

answered 2013-01-19 09:52:35 +0800

Eustas gravatar image Eustas
75 1

updated 2013-01-19 10:06:43 +0800

Thanks. Can I use this approach for mvvm case?
Actually my page constructed in such way:

<window id="myWin"  apply="org.zkoss.bind.BindComposer"  viewModel="@id('vm')  @init('com.mvvm.DesktopViewModel')">

  <button label="Add and close window"  onClick="@command('addPeopleToList')" >  //here I have to close window

My code


public class MyViewModel
 {
     private Window modalWindow;

     public void openModalWindow(String pageName)
    {
        modalWindow = (Window) Executions.createComponents(pageName, null, null);
        modalWindow.doModal();
    }

     public void addPeopleToList()
    {
        modalWindow.detach(); //HERE I GET NULLPOINTEREXCEPTION - modalWindow is null
    }
     
}

What difference with your approach?

link publish delete flag offensive edit
0

answered 2013-01-19 05:50:56 +0800

zerocold gravatar image zerocold
128 1

updated 2013-01-19 05:51:30 +0800

you can use:

this is extends GenericForwardComposer, you only change to SelectComposer as you using

private Window modalDialog;

public void onClick$closeBtn(Event event) throws Exception {
		modalDialog.detach();
	}

modalDialog is your window ID

link publish delete flag offensive edit
0

answered 2013-01-19 00:46:34 +0800

jj gravatar image jj
638 3

Haven't used MVVM much, since it appears that I always much finer control with the UI. However, I think you should look into "Global Command" in the documentation.

link publish delete flag offensive edit

Question tools

Follow

RSS

Stats

Asked: 2013-01-18 20:54:43 +0800

Seen: 89 times

Last updated: Jan 21 '13

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