2、MVC处理部分的Action代码
在EasyJF的会议系统中,由于使用EasyJWeb作为MVC框架,因此处理Ajax比较简单,下面是会议室系统的核心Action主要代码。
package com.easyjf.chat.action;
public class ChatAction extends AbstractCmdAction {
private ChatService chatRoom;
public Object doBefore(WebForm form, Module module) {
// TODO Auto-generated method stub
if(chatRoom==null)chatRoom=ChatService.get((String)form.get("cid"));
return super.doBefore(form, module);
}
public Page doInit(WebForm form, Module module) {
// TODO Auto-generated method stub
return doMain(form,module);
}
//用户登录进入会议室
public Page doMain(WebForm form, Module module) {
if(chatRoom!=null){
ChatUser user=getChatUser();
if(!chatRoom.join(user))form.addResult("msg","不能加入房间,可能是权限不够!");
form.addResult("chatRoom",chatRoom);
form.addResult("user",user);
}
else
{
form.addResult("msg","会议未启动或者会议室不存在!");
}
return module.findPage("main");
}
//处理用户发言信息
public Page doSend(WebForm form, Module module) {
if(chatRoom==null)return new Page("err","/err.html","thml");//返回会议室不存在的错误
Chat chat=(Chat)form.toPo(Chat.class);
chat.setCid(chatRoom.geneId());
chatRoom.talk(chat);
return doRecive(form,module);
}
//用户接收发言信息
public Page doRecive(WebForm form, Module module) {
if(chatRoom==null)return new Page("err","/err.html","thml");//返回会议室不存在的错误
String lastReadId=CommUtil.null2String(form.get("lastReadId"));
//System.out.println(lastReadId);
form.addResult("list", chatRoom.getNewestMsg(getChatUser(),lastReadId));
return module.findPage("msgList");
}
//用户刷新会议状态信息
public Page doLoadConfig(WebForm form, Module module) {
if(chatRoom==null)return new Page("err","/err.html","thml");//返回会议室不存在的错误
form.addResult("userList", chatRoom.getUsers());
form.addResult("talkerList", chatRoom.getTalkers());
return module.findPage("config");
}
//用户退出
public Page doExit(WebForm form, Module module) {
if(chatRoom==null)return new Page("err","/err.html","thml");//返回会议室不存在的错误
chatRoom.exit(getChatUser());
form.addResult("msg","退出成功");
ActionContext.getContext().getSession().removeAttribute("chatUser");
return new Page("msg","/chat/xmlMsg.xml",Globals.PAGE_TEMPLATE_TYPE);
}
3、客户端AJAX部分核心代码
EasyJF会议系统中,服务器发送给客户端的都是格式化的xml文档数据。下面是核心的AJAX函数及发送接收会议信息的客户端代码。
评论加载中…
![]() |