-
FEATURED COMPONENTS
First time here? Check out the FAQ!
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?
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 } }
@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
Check here
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?
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
Asked: 2013-01-18 20:54:43 +0800
Seen: 89 times
Last updated: Jan 21 '13