-
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 ?
ParentWindow.zul
<?page title="Parent Window" contentType="text/html;charset=UTF-8"?>
<zk> <window id="parentWindow" title="Parent Window" border="normal" apply="org.com.demo.ParentWindowController"> <label value="First Name"></label> <separator></separator> <textbox id="firstName"></textbox> <separator></separator> <label value="Last Name"></label> <separator></separator> <textbox id="lastName"></textbox> <separator></separator> <button label="Show Window" id="showWindow"></button> </window> </zk>
ParentWindowController.java
package org.com.demo;
import java.util.HashMap;
import org.zkoss.zk.ui.Component; 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 SelectorComposer<window> {
@Wire
private Window parentWindow;
@Wire
Textbox firstName;
@Wire
Textbox lastName;
@SuppressWarnings({ "rawtypes", "unchecked" })
public void doAfterCompose(Window comp) throws Exception {
super.doAfterCompose(comp); // wire variables and event listners
}
@Listen("onClick=#showWindow")
public void showChild() {
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");
}
}
ChildWindow.zul
<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" arg0="childwindow" ?>
<zk> <window id="childwindow" title="Child Window" border="normal" mode="modal" width="30%" apply="org.com.demo.ChildWindowController"> <label value="Change the first name and Last name and click the button close to return the values"></label> <separator></separator> <label value="First Name"></label> <separator></separator> <textbox id="firstName" value="@{childwindow$ChildWindowController.firstName}"></textbox> <separator></separator> <label value="Last Name"></label> <separator></separator> <textbox id="lastName" value="@{childwindow$ChildWindowController.lastName}"> </textbox> <separator></separator> <separator></separator> <button id="btn" label="Close"></button> </window> </zk>
ChildWindowController
package org.com.demo;
import java.util.HashMap;
import org.zkoss.zk.ui.Component; import org.zkoss.zk.ui.Execution; import org.zkoss.zk.ui.Executions; import org.zkoss.zk.ui.event.Event; import org.zkoss.zk.ui.event.EventQueue; import org.zkoss.zk.ui.event.EventQueues; import org.zkoss.zk.ui.event.Events; 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.zul.Button; import org.zkoss.zul.Messagebox; import org.zkoss.zul.Textbox; import org.zkoss.zul.Window;
@SuppressWarnings("serial") public class ChildWindowController extends SelectorComposer<component> {
@Wire
Button btn;
@Wire
Window childwindow;
private Window parentWindow;
private String firstName;
private String lastName;
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public void doAfterCompose(Component comp) throws Exception {
super.doAfterCompose(comp);
final Execution execution = Executions.getCurrent();
setFirstName((String) execution.getArg().get("firstName"));
setLastName((String) execution.getArg().get("lastName"));
parentWindow = (Window) execution.getArg().get("parentWindow");
}
@Listen("onClick = button#btn")
public void changeLabel() {
final HashMap<String, Object> map = new HashMap<String, Object>();
map.put("firstName", this.firstName);
map.put("lastName", this.lastName);
childwindow.detach();
Events.sendEvent(new Event("onSaved", parentWindow));
}
}
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
Asked: 2013-02-06 02:39:19 +0800
Seen: 21 times
Last updated: Feb 06 '13