DWR3.0推送
回头不看 2011-05-05 10:44:38 最近在学DWR3.0推送的时候
String page = WebContextFactory.get().getContextPath() + "/index.jsp";
Browser.withPage(page, new Runnable() {
public void run() {
Util.setValue("clockDisplay", "发布消息啦!");
}
});
就是说我在chat.jsp发布一个消息时 如何才能将我要发布的消息推送到index.jsp页面上!
好像每次测试时
运行上面的方法时不运行到run方法
但是运行
// 推给所有用户
Browser.withAllSessions(new Runnable() {
public void run() {
Util.removeAllOptions("users");
Util.addOptions("users", users, "name");
Util.removeAllOptions("receiver");
Util.addOptions("receiver", users, "name");
}
});
// 推给指定用户
Browser.withCurrentPageFiltered(new ScriptSessionFilter() {
public boolean match(ScriptSession session) {
if (session.getAttribute("user") == null)
return false;
else
return ((User) session.getAttribute("user")).getName()
.equals(receiverid);
}
}, new Runnable() {
public void run() {
Collection<ScriptSession> colls = Browser.getTargetSessions();
for (ScriptSession scriptSession : colls) {
scriptSession.addScript(initFunctionCall(
"dwr.util.setValue", "sender", sender));
scriptSession.addScript(initFunctionCall(
"dwr.util.setValue", "msg", msg));
}
ScriptBuffer script = new ScriptBuffer();
script.appendScript("showMessage(").appendData(msg)
.appendScript(");");
}
});
这两个方法的时候没有问题 请问大家 是不是推送到指定页面要加什么特殊的配置吗?