• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

moto web application


Commit MetaInfo

Revisione31aeeecdfda5a9d6275429f42fad879fc157fd3 (tree)
Time2014-01-30 11:40:10
Authorastoria-d <astoria-d@mail...>
Commiterastoria-d

Log Message

push socket unified

Change Summary

Incremental Difference

--- a/WEB-INF/classes/motoSample/ChatBean.java
+++ b/WEB-INF/classes/motoSample/ChatBean.java
@@ -215,14 +215,14 @@ public class ChatBean implements Serializable {
215215
216216 conn.close();
217217
218- PushContext pushContext = PushContextFactory.getDefault().getPushContext();
219-
220- ChatBean.ChatMessage cm = new ChatBean.ChatMessage();
218+ PushMsg pm = PushMsg.newChatMessage();
219+ PushMsg.ChatMessage cm = pm.getChatMessage();
221220 cm.setMsg(msg);
222221 cm.setDate(dt);
223222 cm.setUname(userBean.getUid());
224223
225- pushContext.push("/" + chatRoom, cm);
224+ PushContext pushContext = PushContextFactory.getDefault().getPushContext();
225+ pushContext.push("/" + chatRoom, pm);
226226 }
227227 catch (SQLException se) {
228228 log.severe("sql err!!!");
--- /dev/null
+++ b/WEB-INF/classes/motoSample/PushMsg.java
@@ -0,0 +1,56 @@
1+package motoSample;
2+
3+
4+public class PushMsg {
5+
6+ public static class LoginUser {
7+ String uid;
8+ boolean login;
9+
10+ public void setUid(String uid) { this.uid = uid; }
11+ public void setLogin(boolean login) { this.login = login; }
12+ public String getUid() { return uid; }
13+ public boolean getLogin() { return login; }
14+ }
15+
16+ public static class ChatMessage {
17+ private String uname;
18+ private String msg;
19+ private String date;
20+
21+ public String getUname() { return uname; }
22+ public String getMsg() { return msg; }
23+ public String getDate() { return date; }
24+ public void setUname(String uname) { this.uname = uname; }
25+ public void setMsg(String msg) { this.msg = msg; }
26+ public void setDate(String date) { this.date = date; }
27+ }
28+
29+ private String pushType;
30+ private LoginUser lu;
31+ private ChatMessage cm;
32+
33+ public String getPushType() { return pushType; }
34+ public void setPushType(String pushType) { this.pushType = pushType; }
35+ public LoginUser getLoginUser () { return lu; }
36+ public void setLoginUser (LoginUser lu) { this.lu = lu; }
37+ public ChatMessage getChatMessage () { return cm; }
38+ public void setChatMessage (ChatMessage cm) { this.cm = cm; }
39+
40+ public final static String PUSH_TYPE_LOGIN = "PUSH_TYPE_LOGIN";
41+ public final static String PUSH_TYPE_CHAT_MESSAGE = "PUSH_TYPE_CHAT_MESSAGE";
42+
43+ public static PushMsg newLoginPushMsg() {
44+ PushMsg pm = new PushMsg();
45+ pm.setPushType(PUSH_TYPE_LOGIN);
46+ pm.setLoginUser(new LoginUser());
47+ return pm;
48+ }
49+
50+ public static PushMsg newChatMessage() {
51+ PushMsg pm = new PushMsg();
52+ pm.setPushType(PUSH_TYPE_CHAT_MESSAGE);
53+ pm.setChatMessage(new ChatMessage());
54+ return pm;
55+ }
56+}
--- a/WEB-INF/classes/motoSample/UserBean.java
+++ b/WEB-INF/classes/motoSample/UserBean.java
@@ -90,14 +90,6 @@ public class UserBean implements Serializable {
9090 }
9191 }
9292
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- }
10193 public String doLogin() {
10294
10395 try {
@@ -130,12 +122,14 @@ public class UserBean implements Serializable {
130122 //notify log in message
131123 for (SelectItem si : flights) {
132124 String chatRoom = si.getValue().toString();
133- LoginUser lu = new LoginUser();
125+
126+ PushMsg pm = PushMsg.newLoginPushMsg();
127+ PushMsg.LoginUser lu = pm.getLoginUser();
134128 lu.setUid(uid);
135129 lu.setLogin(true);
136130
137131 PushContext pushContext = PushContextFactory.getDefault().getPushContext();
138- pushContext.push("/login_" + chatRoom, lu);
132+ pushContext.push("/" + chatRoom, pm);
139133 }
140134
141135 ///after login, redirect to the user specified url.
@@ -167,15 +161,17 @@ public class UserBean implements Serializable {
167161 //notify log in message
168162 for (SelectItem si : flights) {
169163 String chatRoom = si.getValue().toString();
170- LoginUser lu = new LoginUser();
164+ PushMsg pm = PushMsg.newLoginPushMsg();
165+ PushMsg.LoginUser lu = pm.getLoginUser();
171166 lu.setUid(uid);
172167 lu.setLogin(false);
173168
174169 PushContext pushContext = PushContextFactory.getDefault().getPushContext();
175- pushContext.push("/login_" + chatRoom, lu);
170+ pushContext.push("/" + chatRoom, pm);
176171 }
177172 loginMemberBean.login(uid, false);
178173 context.getExternalContext().invalidateSession();
174+ //login = false;
179175 return "/login.jsf";
180176 }
181177
--- a/secured/chat.xhtml
+++ b/secured/chat.xhtml
@@ -4,12 +4,24 @@
44 xmlns:f="http://java.sun.com/jsf/core"
55 xmlns:ui="http://java.sun.com/jsf/facelets">
66
7- <ui:composition template="/WEB-INF/templates/moto-template.xhtml">
7+ <ui:composition
8+ template="/WEB-INF/templates/moto-template.xhtml"
9+ xmlns:p="http://primefaces.org/ui"
10+ >
811 <ui:define name="pageTitle">jsf chat app</ui:define>
912
1013 <ui:define name="ext-html-header">
1114 <script type="text/javascript">
1215 //<![CDATA[
16+ function handleMessage(data) {
17+ if (data.pushType == 'PUSH_TYPE_CHAT_MESSAGE') {
18+ handleChatMsg(data.chatMessage);
19+ }
20+ else if (data.pushType == 'PUSH_TYPE_LOGIN') {
21+ handleLogin(data.loginUser);
22+ }
23+ }
24+
1325 function handleChatMsg(data) {
1426 var msgList = document.getElementById("chatForm:msgList");
1527
@@ -46,6 +58,9 @@
4658
4759 //]]>
4860 </script>
61+
62+<p:socket onMessage="handleMessage" channel="/#{chatBean.chatRoom}" />
63+
4964 </ui:define>
5065
5166 <ui:define name="pageHeader" />
@@ -56,16 +71,10 @@
5671 <h:outputText value="#{chatBean.viewId}"/>
5772 <br />
5873
59- <h:form id="chatForm"
60- xmlns:a4j="http://richfaces.org/a4j"
61- xmlns:p="http://primefaces.org/ui"
62- xmlns:rich="http://richfaces.org/rich">
74+ <h:form id="chatForm">
6375
6476 <h:inputHidden id="viewId" value="#{chatBean.viewId}"/>
6577
66-<p:socket onMessage="handleChatMsg" channel="/#{chatBean.chatRoom}" />
67-<p:socket onMessage="handleLogin" channel="/login_#{chatBean.chatRoom}" />
68-
6978 chat room :
7079 <h:selectOneMenu id="chatRoom" value="#{chatBean.chatRoom}" onchange="submit()"
7180 valueChangeListener="#{chatBean.chatRoomChanged}" >