moto web application
修订版 | dd09028d2ca1c566b67de29c7ab6d6cf0ea074f8 (tree) |
---|---|
时间 | 2014-01-29 15:41:36 |
作者 | astoria-d <astoria-d@mail...> |
Commiter | astoria-d |
push clean up, jms not to be used.
@@ -27,11 +27,7 @@ import javax.faces.component.html.HtmlCommandLink; | ||
27 | 27 | import java.util.Date; |
28 | 28 | import java.text.SimpleDateFormat; |
29 | 29 | import java.util.UUID; |
30 | -/* | |
31 | -import org.richfaces.application.push.TopicKey; | |
32 | -import org.richfaces.application.push.TopicsContext; | |
33 | -import org.richfaces.application.push.MessageException; | |
34 | -*/ | |
30 | + | |
35 | 31 | import org.primefaces.push.PushContext; |
36 | 32 | import org.primefaces.push.PushContextFactory; |
37 | 33 |
@@ -49,9 +45,6 @@ public class ChatBean implements Serializable { | ||
49 | 45 | @ManagedProperty("#{userBean}") |
50 | 46 | private UserBean userBean; |
51 | 47 | |
52 | - @ManagedProperty("#{pushBean}") | |
53 | - private PushBean pushBean; | |
54 | - | |
55 | 48 | @ManagedProperty("#{loginMemberBean}") |
56 | 49 | private LoginMemberBean loginMemberBean; |
57 | 50 |
@@ -104,9 +97,6 @@ public class ChatBean implements Serializable { | ||
104 | 97 | public void setUserBean(UserBean userBean) { |
105 | 98 | this.userBean = userBean; |
106 | 99 | } |
107 | - public void setPushBean(PushBean pushBean) { | |
108 | - this.pushBean = pushBean; | |
109 | - } | |
110 | 100 | public void setLoginMemberBean(LoginMemberBean loginMemberBean) { |
111 | 101 | this.loginMemberBean = loginMemberBean; |
112 | 102 | } |
@@ -136,13 +126,6 @@ public class ChatBean implements Serializable { | ||
136 | 126 | } |
137 | 127 | } |
138 | 128 | |
139 | - public class ViewMsgList { | |
140 | - public String viewId; | |
141 | - public String chatRoom; | |
142 | - public ArrayList<ChatMessage> msgList; | |
143 | - public MemberList memList; | |
144 | - } | |
145 | - | |
146 | 129 | private void initMsgList(){ |
147 | 130 | log.info("initMsgList: " + chatRoom + ", msgList: " |
148 | 131 | + (msgList == null ? "null" : msgList.hashCode()) + ", viewId: " + getViewId()); |
@@ -179,60 +162,9 @@ public class ChatBean implements Serializable { | ||
179 | 162 | catch (SQLException se) { |
180 | 163 | log.severe("sql err!!!"); |
181 | 164 | } |
182 | - | |
183 | - //register viewlist in the session to receive ajax push notification update. | |
184 | - HttpSession session = (HttpSession) context.getExternalContext().getSession(true); | |
185 | - ArrayList<ViewMsgList> viewList = (ArrayList<ViewMsgList>) session.getAttribute("viewList"); | |
186 | - if (viewList == null) { | |
187 | - viewList = new ArrayList<ViewMsgList>(); | |
188 | - session.setAttribute("viewList", viewList); | |
189 | - } | |
190 | - ViewMsgList vml = new ViewMsgList(); | |
191 | - vml.viewId = viewId; | |
192 | - vml.chatRoom = chatRoom; | |
193 | - vml.msgList = msgList; | |
194 | - putViewList(viewList, vml); | |
195 | 165 | } |
196 | - | |
197 | - private static int MAX_VIEW_LIST_CNT = 3; | |
198 | - void putViewList(ArrayList<ViewMsgList> viewList, ViewMsgList vml) { | |
199 | - int i; | |
200 | - for (i = 0; i < viewList.size(); i++ ) { | |
201 | - ViewMsgList it_vml = viewList.get(i); | |
202 | - if (vml.viewId.equals(it_vml.viewId)) { | |
203 | - viewList.set(i, vml); | |
204 | - return; | |
205 | - } | |
206 | - } | |
207 | - viewList.add(vml); | |
208 | - if (viewList.size() > MAX_VIEW_LIST_CNT) { | |
209 | - //view number control. | |
210 | - ViewMsgList rm_vml = viewList.remove(0); | |
211 | - rm_vml.msgList.clear(); | |
212 | - | |
213 | - ChatMessage m = new ChatMessage(); | |
214 | - m.uname = "----"; | |
215 | - m.msg = "too much view is opened. please close this window (or tab)."; | |
216 | - m.date = "----"; | |
217 | - rm_vml.msgList.add(m); | |
218 | 166 | |
219 | - /* | |
220 | - //notify browser. | |
221 | - try { | |
222 | - TopicKey topicKey = new TopicKey(rm_vml.viewId); | |
223 | - TopicsContext topicsContext = TopicsContext.lookup(); | |
224 | - topicsContext.publish(topicKey, "notify"); | |
225 | - } | |
226 | - catch (MessageException me) { | |
227 | - log.severe("message exeption!!"); | |
228 | - } | |
229 | - */ | |
230 | - | |
231 | - log.info("old viewList is removed."); | |
232 | - } | |
233 | - } | |
234 | - | |
235 | - public ArrayList<ChatMessage> getMsgList(){ | |
167 | + public ArrayList<ChatMessage> getMsgList(){ | |
236 | 168 | // log.info("getMsgList"); |
237 | 169 | // try { |
238 | 170 | //System.out.print("viewId:" + viewId); |
@@ -295,8 +227,6 @@ public class ChatBean implements Serializable { | ||
295 | 227 | catch (SQLException se) { |
296 | 228 | log.severe("sql err!!!"); |
297 | 229 | } |
298 | - | |
299 | - //pushBean.pushChatMessage(viewId, chatRoom, msg, userBean.getUid(), dt); | |
300 | 230 | } |
301 | 231 | |
302 | 232 | public void loadOldMsg() { |
@@ -347,17 +277,6 @@ public class ChatBean implements Serializable { | ||
347 | 277 | memList.setChatRoom(chatRoom); |
348 | 278 | memList.setLoginMember(loginMemberBean); |
349 | 279 | memList.initMemList(); |
350 | - | |
351 | - //register viewlist in the session to receive ajax push notification update. | |
352 | - HttpSession session = (HttpSession) context.getExternalContext().getSession(true); | |
353 | - ArrayList<ViewMsgList> viewList = (ArrayList<ViewMsgList>) session.getAttribute("viewList"); | |
354 | - for (ViewMsgList vml : viewList) { | |
355 | - if (vml.viewId.equals(viewId)) { | |
356 | - vml.memList = memList; | |
357 | - break; | |
358 | - } | |
359 | - } | |
360 | - | |
361 | 280 | } |
362 | 281 | ///chat room menu value changed listener |
363 | 282 | public void chatRoomChanged(ValueChangeEvent e) { |
@@ -1,300 +0,0 @@ | ||
1 | -package motoSample; | |
2 | - | |
3 | -import java.io.Serializable; | |
4 | -import javax.faces.bean.ManagedBean; | |
5 | -import javax.faces.bean.SessionScoped; | |
6 | -import javax.faces.bean.ManagedProperty; | |
7 | -import javax.faces.context.FacesContext; | |
8 | -import javax.faces.event.ActionEvent; | |
9 | -import javax.faces.component.UIComponent; | |
10 | -import javax.faces.component.UIInput; | |
11 | - | |
12 | -import javax.servlet.http.HttpSession; | |
13 | - | |
14 | -import java.util.logging.Logger; | |
15 | -import javax.inject.Inject; | |
16 | -import javax.annotation.PostConstruct; | |
17 | -import javax.annotation.PreDestroy; | |
18 | - | |
19 | -/* | |
20 | -import org.richfaces.application.push.TopicKey; | |
21 | -import org.richfaces.application.push.TopicsContext; | |
22 | -import org.richfaces.application.push.MessageException; | |
23 | -*/ | |
24 | -import javax.jms.MessageListener; | |
25 | -import javax.jms.Message; | |
26 | -import javax.jms.MapMessage; | |
27 | - | |
28 | -import javax.naming.Context; | |
29 | -import javax.naming.InitialContext; | |
30 | -import javax.naming.NamingException; | |
31 | - | |
32 | -import java.util.Properties; | |
33 | - | |
34 | -import javax.jms.TopicConnectionFactory; | |
35 | -import javax.jms.TopicConnection; | |
36 | -import javax.jms.Topic; | |
37 | -import javax.jms.Session; | |
38 | -import javax.jms.TopicSession; | |
39 | -import javax.jms.TopicSubscriber; | |
40 | -import javax.jms.TopicPublisher; | |
41 | -import javax.jms.JMSException; | |
42 | - | |
43 | -import java.util.ArrayList; | |
44 | - import java.util.Vector; | |
45 | - import java.util.Iterator; | |
46 | - import javax.faces.model.SelectItem; | |
47 | - | |
48 | - | |
49 | -@ManagedBean | |
50 | -@SessionScoped | |
51 | -public class PushBean implements MessageListener, Serializable { | |
52 | - | |
53 | - @Inject | |
54 | - private Logger log; | |
55 | - | |
56 | - @Inject | |
57 | - private FacesContext context = null; | |
58 | - | |
59 | - private static final String PUSH_TYPE_MSG_POST = "messagePost"; | |
60 | - private static final String PUSH_TYPE_LOG_IN = "login"; | |
61 | - private static final String PUSH_TYPE_LOG_OFF = "logoff"; | |
62 | - | |
63 | - private ArrayList<ChatBean.ViewMsgList> viewList; | |
64 | - | |
65 | - private static final String PUSH_JMS_TOPIC = "motoTest"; | |
66 | - | |
67 | - private TopicConnectionFactory getTopicConnectionFactory() { | |
68 | - try { | |
69 | - return (TopicConnectionFactory) InitialContext.doLookup("java:/ConnectionFactory"); | |
70 | - } catch (NamingException e) { | |
71 | - try { | |
72 | - return (TopicConnectionFactory) InitialContext.doLookup("ConnectionFactory"); | |
73 | - } catch (NamingException e2) { | |
74 | - throw new IllegalStateException("Can't find registered ConnectionFactory"); | |
75 | - } | |
76 | - } | |
77 | - } | |
78 | - | |
79 | - private TopicConnection connection = null; | |
80 | - private TopicSession session = null; | |
81 | - private TopicPublisher publisher = null; | |
82 | - private TopicSubscriber subscriber = null; | |
83 | - | |
84 | - public void initPushBean() { | |
85 | - | |
86 | - log.info("initPushBean"); | |
87 | - | |
88 | - try { | |
89 | - if (connection == null) { | |
90 | - TopicConnectionFactory tcf = getTopicConnectionFactory(); | |
91 | - connection = tcf.createTopicConnection(); | |
92 | - log.info("connection ok."); | |
93 | - } | |
94 | - if (session == null) { | |
95 | - session = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); | |
96 | - log.info("session ok."); | |
97 | - } | |
98 | - | |
99 | - Topic topic = InitialContext.doLookup("topic/" + PUSH_JMS_TOPIC); | |
100 | - log.info("topic ok."); | |
101 | - | |
102 | - if (publisher == null) { | |
103 | - publisher = session.createPublisher(topic); | |
104 | - log.info("publisher ok."); | |
105 | - } | |
106 | - if (subscriber== null) { | |
107 | - subscriber = session.createSubscriber(topic); | |
108 | - log.info("subscriber ok."); | |
109 | - | |
110 | - // Set a JMS message listener | |
111 | - subscriber.setMessageListener(this); | |
112 | - log.info("lisntener bind ok."); | |
113 | - } | |
114 | - | |
115 | - // Start the JMS connection; allows messages to be delivered | |
116 | - connection.start( ); | |
117 | - log.info("connection start ok."); | |
118 | - } | |
119 | - catch (JMSException je) { | |
120 | - log.severe("jms exeption!!!"); | |
121 | - } | |
122 | - catch (NamingException ne) { | |
123 | - log.severe("naming exeption!!!"); | |
124 | - } | |
125 | - | |
126 | - //get list of receiver view of this session.... | |
127 | - HttpSession req_session = (HttpSession) context.getExternalContext().getSession(true); | |
128 | - viewList = (ArrayList<ChatBean.ViewMsgList>) req_session.getAttribute("viewList"); | |
129 | - if (viewList == null) { | |
130 | - viewList = new ArrayList<ChatBean.ViewMsgList>(); | |
131 | - req_session.setAttribute("viewList", viewList); | |
132 | - } | |
133 | - } | |
134 | - | |
135 | - //this method is invoked from the sender side. | |
136 | - public void pushChatMessage(String viewId, String chatRoom, String msg, String uid, String date) { | |
137 | - log.info("push from view " + viewId + ", msg=" + msg); | |
138 | - | |
139 | - try { | |
140 | - MapMessage message = session.createMapMessage(); | |
141 | - message.setString("pushType", PUSH_TYPE_MSG_POST); | |
142 | - message.setString("viewId", viewId); | |
143 | - message.setString("chatRoom", chatRoom); | |
144 | - message.setString("msg", msg); | |
145 | - message.setString("uid", uid); | |
146 | - message.setString("date", date); | |
147 | - publisher.publish(message); | |
148 | - | |
149 | - //deliver jms message | |
150 | - log.info("message published by " + this.hashCode()); | |
151 | - //log.info("context: " + context); | |
152 | - | |
153 | - /* | |
154 | - //notifying ajax is done by the message receiver | |
155 | - TopicKey topicKey = new TopicKey(chatRoom); | |
156 | - TopicsContext topicsContext = TopicsContext.lookup(); | |
157 | - topicsContext.publish(topicKey, "notify"); | |
158 | - */ | |
159 | - } | |
160 | - catch (JMSException je) { | |
161 | - log.severe("jms exeption!!"); | |
162 | - } | |
163 | - } | |
164 | - | |
165 | - //this method is invoked from the sender side. | |
166 | - public void pushLogin(String uid, ArrayList<SelectItem> flights, boolean isLogin) { | |
167 | - log.info("login: " + uid); | |
168 | - try { | |
169 | - MapMessage message = session.createMapMessage(); | |
170 | - message.setString("pushType", PUSH_TYPE_LOG_IN); | |
171 | - message.setString("uid", uid); | |
172 | - message.setBoolean("isLogin", isLogin); | |
173 | - publisher.publish(message); | |
174 | - | |
175 | - //notify ajax page. | |
176 | - for (SelectItem si : flights) { | |
177 | - String chatRoom = si.getValue().toString(); | |
178 | - /* | |
179 | - TopicKey topicKey = new TopicKey("login_" + chatRoom); | |
180 | - TopicsContext topicsContext = TopicsContext.lookup(); | |
181 | - topicsContext.publish(topicKey, "notify"); | |
182 | - */ | |
183 | - } | |
184 | - } | |
185 | - catch (JMSException je) { | |
186 | - log.severe("jms exeption!!"); | |
187 | - } | |
188 | - /* | |
189 | - catch (MessageException je) { | |
190 | - log.severe("message exeption!!"); | |
191 | - }*/ | |
192 | - } | |
193 | - | |
194 | - //this method is invoked on the receiver side. | |
195 | - public void onMessage(Message message) { | |
196 | - //msgCnt++; | |
197 | - log.info("message received by " + this.hashCode()); | |
198 | - //log.info("viewMap size: " + viewMap.size()); | |
199 | - MapMessage mmsg = (MapMessage)message; | |
200 | - | |
201 | - try { | |
202 | - String msgType = mmsg.getString("pushType"); | |
203 | - if (msgType.equals(PUSH_TYPE_MSG_POST)) { | |
204 | - onPostMsgDelivered(mmsg); | |
205 | - } | |
206 | - else if (msgType.equals(PUSH_TYPE_LOG_IN)) { | |
207 | - onLoginDelivered(mmsg); | |
208 | - } | |
209 | - } | |
210 | - catch (JMSException je) { | |
211 | - log.severe("get message error!!"); | |
212 | - } | |
213 | - } | |
214 | - | |
215 | - public void onPostMsgDelivered(MapMessage message) { | |
216 | - for (ChatBean.ViewMsgList vml : viewList) { | |
217 | - //update the view only if it has the same chat room | |
218 | - try { | |
219 | - if (!message.getString("chatRoom").equals(vml.chatRoom)) | |
220 | - continue; | |
221 | - | |
222 | - ChatBean.ChatMessage m = new ChatBean.ChatMessage(); | |
223 | - m.setUname(message.getString("uid")); | |
224 | - m.setMsg(message.getString("msg")); | |
225 | - m.setDate(message.getString("date")); | |
226 | - vml.msgList.add(m); | |
227 | - | |
228 | - log.info("update msgview list!!: " + vml.viewId + "msg: " + message.getString("msg")); | |
229 | - | |
230 | - /* | |
231 | - TopicKey topicKey = new TopicKey(vml.viewId); | |
232 | - TopicsContext topicsContext = TopicsContext.lookup(); | |
233 | - topicsContext.publish(topicKey, "notify"); | |
234 | - */ | |
235 | - } | |
236 | - catch (JMSException je) { | |
237 | - log.severe("get message error!!"); | |
238 | - } | |
239 | - /* | |
240 | - catch (MessageException me) { | |
241 | - log.severe("message exeption!!"); | |
242 | - }*/ | |
243 | - } | |
244 | - } | |
245 | - | |
246 | - public void onLoginDelivered(MapMessage message) { | |
247 | - try { | |
248 | - String uid = message.getString("uid"); | |
249 | - boolean isLogin = message.getBoolean("isLogin"); | |
250 | - | |
251 | - | |
252 | - //check if the chat rooms are connected to the current view. | |
253 | - for (ChatBean.ViewMsgList vml : viewList) { | |
254 | - for (MemberList.ChatMember mc : vml.memList) { | |
255 | - if (mc.getUname().equals(uid)) { | |
256 | - mc.setIsLogin(isLogin); | |
257 | - break; | |
258 | - } | |
259 | - } | |
260 | - } | |
261 | - } | |
262 | - catch (JMSException je) { | |
263 | - log.severe("get message error!!"); | |
264 | - } | |
265 | - | |
266 | - } | |
267 | - | |
268 | - @PreDestroy | |
269 | - public void preDestroy() { | |
270 | - log.info("preDestroy"); | |
271 | - if (publisher != null) { | |
272 | - try { | |
273 | - publisher.close(); | |
274 | - } catch (JMSException e) { | |
275 | - log.severe("unable to close publisher"); | |
276 | - } | |
277 | - } | |
278 | - if (subscriber != null) { | |
279 | - try { | |
280 | - subscriber.close(); | |
281 | - } catch (JMSException e) { | |
282 | - log.severe("unable to close subscriber"); | |
283 | - } | |
284 | - } | |
285 | - if (session != null) { | |
286 | - try { | |
287 | - session.close(); | |
288 | - } catch (JMSException e) { | |
289 | - log.severe("unable to close session"); | |
290 | - } | |
291 | - } | |
292 | - if (connection != null) { | |
293 | - try { | |
294 | - connection.close(); | |
295 | - } catch (JMSException e) { | |
296 | - log.severe("unable to close connection"); | |
297 | - } | |
298 | - } | |
299 | - } | |
300 | -} |
@@ -18,6 +18,9 @@ import javax.servlet.http.HttpSession; | ||
18 | 18 | import java.util.ArrayList; |
19 | 19 | import javax.faces.model.SelectItem; |
20 | 20 | |
21 | +import org.primefaces.push.PushContext; | |
22 | +import org.primefaces.push.PushContextFactory; | |
23 | + | |
21 | 24 | @ManagedBean |
22 | 25 | @SessionScoped |
23 | 26 | public class UserBean implements Serializable { |
@@ -27,14 +30,9 @@ public class UserBean implements Serializable { | ||
27 | 30 | @Inject |
28 | 31 | private FacesContext context; |
29 | 32 | |
30 | - @ManagedProperty("#{pushBean}") | |
31 | - private PushBean pushBean; | |
32 | 33 | @ManagedProperty("#{loginMemberBean}") |
33 | 34 | private LoginMemberBean loginMemberBean; |
34 | 35 | |
35 | - public void setPushBean(PushBean pushBean) { | |
36 | - this.pushBean = pushBean; | |
37 | - } | |
38 | 36 | public void setLoginMemberBean(LoginMemberBean loginMemberBean) { |
39 | 37 | this.loginMemberBean = loginMemberBean; |
40 | 38 | } |
@@ -91,7 +89,15 @@ public class UserBean implements Serializable { | ||
91 | 89 | log.severe("sql flight err!!!"); |
92 | 90 | } |
93 | 91 | } |
94 | - | |
92 | + | |
93 | + public static class LoginUser { | |
94 | + String uid; | |
95 | + boolean login; | |
96 | + public void setUid(String uid) { this.uid = uid; } | |
97 | + public void setLogin(boolean login) { this.login = login; } | |
98 | + public String getUid() { return uid; } | |
99 | + public boolean getLogin() { return login; } | |
100 | + } | |
95 | 101 | public String doLogin() { |
96 | 102 | |
97 | 103 | try { |
@@ -122,12 +128,18 @@ public class UserBean implements Serializable { | ||
122 | 128 | //add to the app login list. |
123 | 129 | loginMemberBean.login(uid, true); |
124 | 130 | //notify log in message |
125 | - pushBean.initPushBean(); | |
126 | - pushBean.pushLogin(uid, flights, true); | |
127 | - | |
128 | - HttpSession session = Resources.getSession(); | |
131 | + for (SelectItem si : flights) { | |
132 | + String chatRoom = si.getValue().toString(); | |
133 | + LoginUser lu = new LoginUser(); | |
134 | + lu.setUid(uid); | |
135 | + lu.setLogin(true); | |
136 | + | |
137 | + PushContext pushContext = PushContextFactory.getDefault().getPushContext(); | |
138 | + pushContext.push("/login_" + chatRoom, lu); | |
139 | + } | |
129 | 140 | |
130 | 141 | ///after login, redirect to the user specified url. |
142 | + HttpSession session = Resources.getSession(); | |
131 | 143 | String request_url = (String) session.getAttribute("request_url"); |
132 | 144 | if (request_url == null) |
133 | 145 | request_url = "secured/chat.jsf"; |
@@ -152,7 +164,16 @@ public class UserBean implements Serializable { | ||
152 | 164 | } |
153 | 165 | |
154 | 166 | public String doLogout() { |
155 | - pushBean.pushLogin(uid, flights, false); | |
167 | + //notify log in message | |
168 | + for (SelectItem si : flights) { | |
169 | + String chatRoom = si.getValue().toString(); | |
170 | + LoginUser lu = new LoginUser(); | |
171 | + lu.setUid(uid); | |
172 | + lu.setLogin(false); | |
173 | + | |
174 | + PushContext pushContext = PushContextFactory.getDefault().getPushContext(); | |
175 | + pushContext.push("/login_" + chatRoom, lu); | |
176 | + } | |
156 | 177 | loginMemberBean.login(uid, false); |
157 | 178 | context.getExternalContext().invalidateSession(); |
158 | 179 | return "/login.jsf"; |
@@ -3,13 +3,6 @@ | ||
3 | 3 | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"> |
4 | 4 | |
5 | 5 | <application> |
6 | - <!-- push topic initializer registration --> | |
7 | - <!-- not needed ???? | |
8 | - system-event-listener> | |
9 | - <system-event-listener-class>motoSample.TopicsInitializer</system-event-listener-class> | |
10 | - <system-event-class>javax.faces.event.PostConstructApplicationEvent</system-event-class> | |
11 | - </system-event-listener --> | |
12 | 6 | </application> |
13 | 7 | |
14 | - | |
15 | 8 | </faces-config> |
\ No newline at end of file |
@@ -1,9 +1,5 @@ | ||
1 | 1 | <?xml version="1.0" encoding="UTF-8"?> |
2 | 2 | <jboss-deployment-structure> |
3 | 3 | <deployment> |
4 | - <dependencies> | |
5 | - <module name="org.w3c.css.sac" /> | |
6 | - <module name="net.sourceforge.cssparser" /> | |
7 | - </dependencies> | |
8 | 4 | </deployment> |
9 | 5 | </jboss-deployment-structure> |
@@ -43,28 +43,6 @@ | ||
43 | 43 | <auth-constraint> |
44 | 44 | </auth-constraint> |
45 | 45 | </security-constraint> |
46 | - | |
47 | - <!-- enable richfaces push/jms --> | |
48 | - <context-param> | |
49 | - <param-name>org.richfaces.push.initializeOnStartup</param-name> | |
50 | - <param-value>true</param-value> | |
51 | - </context-param> | |
52 | - <context-param> | |
53 | - <param-name>org.richfaces.push.jms.enabled</param-name> | |
54 | - <param-value>false</param-value> | |
55 | - </context-param> | |
56 | - <context-param> | |
57 | - <param-name>org.richfaces.push.jms.connectionUsername</param-name> | |
58 | - <param-value>jmsuser</param-value> | |
59 | - </context-param> | |
60 | - <context-param> | |
61 | - <param-name>org.richfaces.push.jms.connectionPassword</param-name> | |
62 | - <param-value>jmspassword</param-value> | |
63 | - </context-param> | |
64 | - <session-config> | |
65 | - <session-timeout>15</session-timeout> | |
66 | - </session-config> | |
67 | - | |
68 | 46 | |
69 | 47 | <!-- primefaces push servlet --> |
70 | 48 | <servlet> |
@@ -25,7 +25,6 @@ | ||
25 | 25 | <property name="inject" value="${env.JBOSS_HOME}\modules\javax\inject\api\main\javax.inject-1.jar"/> |
26 | 26 | <property name="servlet" value="${env.JBOSS_HOME}\modules\javax\servlet\api\main\jboss-servlet-api_3.0_spec-1.0.0.Final.jar"/> |
27 | 27 | <property name="cdi" value="${env.JBOSS_HOME}\modules\javax\enterprise\api\main\cdi-api-1.0-SP4.jar"/> |
28 | - <property name="jms" value="${env.JBOSS_HOME}\modules\javax\jms\api\main\jboss-jms-api_1.1_spec-1.0.0.Final.jar"/> | |
29 | 28 | <property name="primefaces" value="${lib}\primefaces-4.0.jar"/> |
30 | 29 | <property name="atmosphere" value="${lib}\atmosphere-runtime-2.0.1.jar"/> |
31 | 30 | <property name="slf4j" value="${lib}\slf4j-api-1.6.1.jar"/> |
@@ -56,7 +55,6 @@ | ||
56 | 55 | <pathelement path="${inject}" /> |
57 | 56 | <pathelement path="${servlet}" /> |
58 | 57 | <pathelement path="${cdi}" /> |
59 | - <pathelement path="${jms}" /> | |
60 | 58 | <pathelement path="${primefaces}" /> |
61 | 59 | </classpath> |
62 | 60 | </javac> |
@@ -25,7 +25,25 @@ | ||
25 | 25 | |
26 | 26 | var msg = document.getElementById("chatForm:msg"); |
27 | 27 | msg.value = ''; |
28 | - } | |
28 | + } | |
29 | + | |
30 | + function handleLogin(data) { | |
31 | + var memList = document.getElementById("chatForm:memList"); | |
32 | + var uid = data.uid; | |
33 | + var login = data.login | |
34 | + var i; | |
35 | + for (i = 0; i < memList.rows.length; i++) { | |
36 | + if (memList.rows[i].cells[0].innerHTML.trim() == uid) { | |
37 | + if (login) | |
38 | + memList.rows[i].cells[1].innerHTML = "online"; | |
39 | + else | |
40 | + memList.rows[i].cells[1].innerHTML = "offline"; | |
41 | + break; | |
42 | + } | |
43 | + } | |
44 | + | |
45 | + } | |
46 | + | |
29 | 47 | //]]> |
30 | 48 | </script> |
31 | 49 | </ui:define> |
@@ -46,13 +64,7 @@ | ||
46 | 64 | <h:inputHidden id="viewId" value="#{chatBean.viewId}"/> |
47 | 65 | |
48 | 66 | <p:socket onMessage="handleChatMsg" channel="/#{chatBean.chatRoom}" /> |
49 | - | |
50 | - <!-- a4j:push address="login_#{chatBean.chatRoom}"> | |
51 | - <a4j:ajax event="dataavailable" render="memList" /> | |
52 | - </a4j:push> | |
53 | - <a4j:push address="#{chatBean.viewId}"> | |
54 | - <a4j:ajax event="dataavailable" render="chatTable" /> | |
55 | - </a4j:push --> | |
67 | +<p:socket onMessage="handleLogin" channel="/login_#{chatBean.chatRoom}" /> | |
56 | 68 | |
57 | 69 | chat room : |
58 | 70 | <h:selectOneMenu id="chatRoom" value="#{chatBean.chatRoom}" onchange="submit()" |