zoukankan      html  css  js  c++  java
  • pushlet(QQ提示框)

    Pushlet 实现服务端往客服端推送消息

    系统页面弹出消息框,类似QQ提示框

    1. java代码

    package com.test.jbpm.common;
    
    import java.io.Serializable;
    import java.util.List;
    import com.test.jbpm.web.action.BaseAction;
    import nl.justobjects.pushlet.core.Dispatcher;
    import nl.justobjects.pushlet.core.Event;
    import nl.justobjects.pushlet.core.Session;
    import nl.justobjects.pushlet.core.SessionManager;
    public class NoticePushlet  extends BaseAction implements Serializable{
    
        // 指定用户id
        public void myUnicast(String user,String message) {
             //必须注册ID  PL.userid="hao";
            if (SessionManager.getInstance().hasSession(user)) {
                SessionManager.getInstance().getSessions();
                Event event = Event.createDataEvent("/flowctrl/main");
                event.setField("noticeKey", message);//内容不能使用中文
                Dispatcher.getInstance().unicast(event, user); 
            } else {
                //Event event = Event.createDataEvent("/jbpm_first/hao");
                //event.setField("noticeKey", "The user:("+user+") not live!");
                //Dispatcher.getInstance().unicast(event, this.getSession().getAttribute("code").toString()); 
                //sDispatcher.getInstance().broadcast(event); 
    //            Session[] sessions = SessionManager.getInstance().getSessions();
    //            for (Session session : sessions) {
    //            }
            }
        }
        public void pushletInterface(List<String> prplflNoticeList) {
            
            Session[] sessions = SessionManager.getInstance().getSessions();
            if (sessions != null && sessions.length > 0) {
                for (Session session : sessions) {
                    String sessionId = session.getId();
                    String comcode = sessionId.split("->")[0];
                    int listLength = 0;
    //                for (PrplflNotice pn : prplflNoticeList) {
    //                    if (comcode.equals(pn.getComcode())) {
    //                        listLength = listLength + 1;
    //                    }
    //                }
    
                    if (listLength > 0) {
                        String msg = "��" + comcode + "���� " + listLength + " ��4S���뼰ʱ���������Ϣ";
                        Event event = Event.createDataEvent("/flowctrl/main");
                        event.setField("noticeKey", msg);
                        Dispatcher.getInstance().unicast(event, sessionId);
                    }
                }
            }
        }
    
    
        public void myBroadcast() {
            Event event = Event.createDataEvent("/flowctrl/main"); �
            event.setField("noticeKey", "Broadcast msg");
            Dispatcher.getInstance().broadcast(event);
        }
    }
    View Code
    2.jsp代码
    需要引入ajax-pushlet-client.js
    <script  type="text/javascript">
        // 消息提醒用js,注册监听
        var usercode = '<%=session.getAttribute("code")%>';
        var timestamp=new Date().getTime();
        PL.userid=usercode;
        //PL.userid=usercode+"->"+timestamp;
        PL.webRoot="${pageContext.request.contextPath}/";
        PL._init();
        PL.joinListen('/flowctrl/main');
        function onData(event) {
              var info=event.get("noticeKey");
              openDia(info);
        }
        
        function openDia(info) {
            document.getElementById('messageInfo').innerHTML = info +'<BR><BR><a href="javascript:void(0);" onclick="deal()" target="page">点击处理(未处理完毕仍可点击以继续)</a>';
            showDiv();
        }
    //消息提示使用
            var divTop,divLeft,divWidth,divHeight,docHeight,docWidth,i = 0;
            function showDiv(){
                try{
                    divTop = parseInt(document.getElementById("dialog").style.top,10);
                    divLeft = parseInt(document.getElementById("dialog").style.left,10);
                    divHeight = parseInt(document.getElementById("dialog").offsetHeight,10);
                    divWidth = parseInt(document.getElementById("dialog").offsetWidth,10);
                    docWidth = document.body.clientWidth;
                    docHeight = document.body.clientHeight;
                    document.getElementById("dialog").style.top = parseInt(document.body.scrollTop,10) + docHeight - divHeight;
                    document.getElementById("dialog").style.left = parseInt(document.body.scrollLeft,10) + docWidth - divWidth;
                    document.getElementById("dialog").style.visibility="visible";
                }
                catch(e){}
            }
            function closeDiv()
            {
                document.getElementById('dialog').style.visibility='hidden';
            }
    </script>
    View Code
  • 相关阅读:
    自动化测试工具Gauge--contexts 与 Tear Down steps
    Redis官网第一次闲逛
    针对 《Linux就该这么学》 之 “第三章---管道符、重定向、环境变量” 摘抄、操练及拓展
    父shell 和 子shell; shell脚本的几种执行方式
    麒麟操作系统操练Linux基操
    HTTP代理
    gcc/g++ 安全编码
    golang 生成rsa秘钥对
    depth of feild
    Emission pass
  • 原文地址:https://www.cnblogs.com/holdon521/p/4505179.html
Copyright © 2011-2022 走看看