final HashMap<String, Object> map = (HashMap<String, Object>) event.getData(); ??
terrytornado ( 2013-02-06 21:42:59 +0800 )edit-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi I followed this post. Based on that i have created a small example.
The problem here is if extends to Selectcomposer, the event is not triggered from the child window to the parent window(Event name is OnSaved)
But if i change to extends GenericForwardComposer, everything working fine. So where is the problem ?
Here is the code
Now if you run, the event onSaved in the ParentWindowController will not trigger.
Now we will change the ParentWindowController such as extends GenericForwardComposer as follows
package org.com.demo;
import java.util.HashMap;
import org.zkoss.zk.ui.Executions; import org.zkoss.zk.ui.SuspendNotAllowedException; import org.zkoss.zk.ui.event.Event; import org.zkoss.zk.ui.event.EventListener; import org.zkoss.zk.ui.event.EventQueue; import org.zkoss.zk.ui.event.EventQueues; import org.zkoss.zk.ui.select.SelectorComposer; import org.zkoss.zk.ui.select.annotation.Listen; import org.zkoss.zk.ui.select.annotation.Wire; import org.zkoss.zk.ui.util.GenericForwardComposer; import org.zkoss.zul.Messagebox; import org.zkoss.zul.Textbox; import org.zkoss.zul.Window;
@SuppressWarnings("serial") public class ParentWindowController extends GenericForwardComposer {
private Window parentWindow;
Textbox firstName;
Textbox lastName;
@SuppressWarnings({ "rawtypes", "unchecked" })
public void doAfterCompose(Window comp) throws Exception {
super.doAfterCompose(comp); // wire variables and event listners
}
public void onClick$showWindow() {
final HashMap<String, Object> map = new HashMap<String, Object>();
map.put("firstName", firstName.getValue());
map.put("lastName", lastName.getValue());
map.put("parentWindow", parentWindow);
Executions.createComponents(
"ChildWindow.zul", null, map);
}
/**
* This method is actualy an event handler triggered only from the Child
* window dialog and it is responsible to reflect the data changes
*
*/
public void onSaved(Event event) {
Messagebox.show("OnSaved");
}
}
Now you can see that messagebox box onsaved.
Why it is not working with selectcomposer ?
Please help me
selectcomposer is ok
in ParentWindowController.java add the following anotation to onSaved method:
@Listen("onSaved = #parentWindow")
so you should see the messagebox
I do that from SelectorComposer.
First show child window
Window win2 = (Window) Executions.createComponents("tablasbasicas/usuariosedit.zul", winUsu, arg);
win2.addEventListener("onAceptar", new EventListener<Event>() {
@Override
public void onEvent(Event event) throws Exception {
SeguUsuariosCTL.this.cargarListado(event.getData());
}
});
win2.doModal();
When i close childwindow, in its selectorcomposer:
Event closeEvent = new Event("onAceptar", this.getSelf(), datos);
Events.sendEvent(closeEvent);
Sorry to re open this question.
Now the event is firing, but i am trying back to update the UI as shown here.
@Listen("onSaved = #parentWindow")
public void onSaved(Event event) {
Messagebox.show("OnSaved" + event.getData());
final HashMap<String, Object> map = (HashMap<String, Object>) event.getData();
final Execution execution = Executions.getCurrent();
Messagebox.show( " " +(String) map.get("firstName"));
setFirstName((String) map.get("firstName"));
setLastName((String) map.get("lastName"));
}
But it is updating the zul file ?
final HashMap<String, Object> map = (HashMap<String, Object>) event.getData(); ??
terrytornado ( 2013-02-06 21:42:59 +0800 )editAsked: 2013-02-06 02:55:40 +0800
Seen: 43 times
Last updated: Feb 06 '13
Please help me.
Senthilchettyin ( 2013-02-06 10:10:12 +0800 )editAny help please on this
Senthilchettyin ( 2013-02-06 11:21:44 +0800 )editSo you will want to send data back to parent viewmodel from child viewmodel?
sjoshi ( 2013-02-06 11:41:47 +0800 )editYes that's right answer
Senthilchettyin ( 2013-02-06 13:27:16 +0800 )edit