ZK 父窗口与子窗口消息交互

父窗口代码:

前台(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();
            }
        });
    }
}

 

转载于:https://www.cnblogs.com/langdangyunliu/p/4322005.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值