父窗口代码:
前台(test.zul)
<?page title="" contentType="text/html;charset=UTF-8"?> <zk xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.zkoss.org/2005/zul" xsi:schemaLocation="http://www.zkoss.org/2005/zul http://www.zkoss.org/2005/zul"> <window id="testWin" border="none" apply="test.test19"> <button id="testBtn" label="测试"/> <label id="testLabel" value="ats了解,他不" /> </window> </zk>
后台(test19.java)
package test; import java.util.HashMap; import java.util.Map; import org.zkoss.zk.ui.Component; import org.zkoss.zk.ui.Executions; import org.zkoss.zk.ui.event.Event; import org.zkoss.zk.ui.event.EventListener; import org.zkoss.zk.ui.event.Events; import org.zkoss.zk.ui.event.ForwardEvent; import org.zkoss.zk.ui.util.GenericAutowireComposer; import org.zkoss.zul.Button; import org.zkoss.zul.Window; public class test19 extends GenericAutowireComposer<Component>{ private static final long serialVersionUID = 1L; private Button testBtn; @Override public void doAfterCompose(Component comp) throws Exception { // TODO Auto-generated method stub super.doAfterCompose(comp); testBtn.addEventListener(Events.ON_CLICK, new EventListener<Event>() { @Override public void onEvent(Event event) throws Exception { // TODO Auto-generated method stub Map<String, String> map = new HashMap<String, String>(); map.put("messageItem", "斩.赤红之瞳");
//map.put("testLabel",testLabel);//将控件传给子窗口进行控制 String url = "Exit.zul"; Window window = (Window)Executions.createComponents(url, null, map); window.doModal(); window.addForward("onRefresh", self, "onKjhen");//1、3参数命名必须以on开关且第三个字母必须大写--见附图 } }); } public void onKjhen(ForwardEvent event){ alert(event.getOrigin().getData().toString()); } }
附图:
子窗口代码:
前台(Exit.zul)
<?page title="" contentType="text/html;charset=UTF-8"?> <zk xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.zkoss.org/2005/zul" xsi:schemaLocation="http://www.zkoss.org/2005/zul http://www.zkoss.org/2005/zul"> <window id="exitWD" title="消息提示框" border="normal" position="center,center" action="show: slideDown;hide: slideUp" width="450px" closable="true" apply="test.Exit"> <div align="center"> <label id="testLb"/> </div> <button id="testBtn" label="按扭"/> </window> </zk>
后台(Exit.java)
package test; import java.util.Map; import org.zkoss.zk.ui.Component; import org.zkoss.zk.ui.Executions; import org.zkoss.zk.ui.Path; import org.zkoss.zk.ui.event.Event; import org.zkoss.zk.ui.event.EventListener; import org.zkoss.zk.ui.event.Events; import org.zkoss.zk.ui.util.GenericForwardComposer; import org.zkoss.zul.Button; import org.zkoss.zul.Label; import org.zkoss.zul.Window; public class Exit extends GenericForwardComposer<Component>{ private static final long serialVersionUID = 1L; Map<?, ?> map; private Label testLb; private Button testBtn; Window exitWD; @Override public void doAfterCompose(Component comp) throws Exception { super.doAfterCompose(comp); //获取父页面的控件 Label testbox = (Label) Path.getComponent("/testWin/testLabel");//格式父窗口id+父窗口子控件id System.out.println(testbox.getValue()); map = Executions.getCurrent().getArg(); if (map.containsKey("messageItem")){ testLb.setValue((String)map.get("messageItem")); } else { testLb.setValue("——————————————"); } testBtn.addEventListener(Events.ON_CLICK, new EventListener<Event>() { @Override public void onEvent(Event event) throws Exception { String abc = "testPass"; Events.postEvent("onRefresh", self, abc); exitWD.detach(); } }); } }