moto web application
Revision | 576daed25801b1f0536b9c6391e7fdd6eed62b3f (tree) |
---|---|
Time | 2014-02-05 15:42:46 |
Author | astoria-d <astoria-d@mail...> |
Commiter | astoria-d |
clean up
@@ -46,7 +46,7 @@ public class ChatBean implements Serializable { | ||
46 | 46 | //inject user bean |
47 | 47 | @ManagedProperty("#{userBean}") |
48 | 48 | private UserBean userBean; |
49 | - | |
49 | + //all login members list | |
50 | 50 | @ManagedProperty("#{loginMemberBean}") |
51 | 51 | private LoginMemberBean loginMemberBean; |
52 | 52 |
@@ -54,8 +54,9 @@ public class ChatBean implements Serializable { | ||
54 | 54 | private String chatRoom; |
55 | 55 | private int oldestChatId; |
56 | 56 | private ArrayList<ChatMessage> msgList; |
57 | + | |
58 | + //members that are associated with this chat room | |
57 | 59 | private MemberList memList; |
58 | - private HtmlCommandLink loadLink; | |
59 | 60 | |
60 | 61 | public final static int LIST_LOAD_SIZE = 10; |
61 | 62 |
@@ -72,14 +73,6 @@ public class ChatBean implements Serializable { | ||
72 | 73 | public String getChatRoom() { |
73 | 74 | return chatRoom; |
74 | 75 | } |
75 | - public void setLoadLink(HtmlCommandLink loadLink) { | |
76 | - //log.info("setLoadLink"); | |
77 | - this.loadLink = loadLink; | |
78 | - } | |
79 | - public HtmlCommandLink getLoadLink() { | |
80 | - //log.info("getLoadLink"); | |
81 | - return loadLink; | |
82 | - } | |
83 | 76 | public MemberList getMemList(){ |
84 | 77 | return memList; |
85 | 78 | } |
@@ -156,17 +149,6 @@ public class ChatBean implements Serializable { | ||
156 | 149 | } |
157 | 150 | |
158 | 151 | public ArrayList<ChatMessage> getMsgList(){ |
159 | -// log.info("getMsgList"); | |
160 | -// try { | |
161 | -/* throw new Exception(); | |
162 | - } | |
163 | - catch (Exception e) { | |
164 | - e.printStackTrace(); | |
165 | - } | |
166 | -*/ | |
167 | - | |
168 | -// if (msgList != null && msgList.size() > 0) | |
169 | -// log.info("getMsgList latest msg: " + msgList.get(msgList.size()-1).msg); | |
170 | 152 | return msgList; |
171 | 153 | } |
172 | 154 |
@@ -181,12 +163,6 @@ public class ChatBean implements Serializable { | ||
181 | 163 | if (msg.equals("")) |
182 | 164 | return; |
183 | 165 | |
184 | - /* | |
185 | - log.info("user = " + userBean.getUid()); | |
186 | - log.info("chat room = " + chatRoom); | |
187 | - log.info("date = " + df.format(d)); | |
188 | - */ | |
189 | - | |
190 | 166 | String dt = formatDate(); |
191 | 167 | try { |
192 | 168 | Connection conn = Resources.getConnection(); |
@@ -256,21 +232,19 @@ public class ChatBean implements Serializable { | ||
256 | 232 | rs.close(); |
257 | 233 | conn.close(); |
258 | 234 | |
235 | + ExternalContext externalContext = context.getExternalContext(); | |
236 | + externalContext.setResponseContentType("application/json"); | |
237 | + externalContext.setResponseCharacterEncoding("UTF-8"); | |
259 | 238 | if (load_cnt == 0) { |
260 | 239 | log.info("no more old msg..."); |
261 | - loadLink.setDisabled(true); | |
262 | - loadLink.setValue("no more old messages...."); | |
263 | 240 | } |
264 | 241 | else { |
265 | 242 | //output json object. |
266 | - ExternalContext externalContext = context.getExternalContext(); | |
267 | - externalContext.setResponseContentType("application/json"); | |
268 | - externalContext.setResponseCharacterEncoding("UTF-8"); | |
269 | 243 | ObjectMapper mapper = new ObjectMapper(); |
270 | 244 | String json = mapper.writeValueAsString(retList); |
271 | 245 | externalContext.getResponseOutputWriter().write(json); |
272 | - context.responseComplete(); | |
273 | 246 | } |
247 | + context.responseComplete(); | |
274 | 248 | } |
275 | 249 | catch (SQLException se) { |
276 | 250 | log.severe("sql err!!!"); |
@@ -281,11 +255,6 @@ public class ChatBean implements Serializable { | ||
281 | 255 | |
282 | 256 | } |
283 | 257 | |
284 | - void initLoadLink() { | |
285 | - loadLink.setDisabled(false); | |
286 | - loadLink.setValue("load old messages..."); | |
287 | - } | |
288 | - | |
289 | 258 | void initMembers() { |
290 | 259 | if (memList == null) |
291 | 260 | memList = new MemberList(); |
@@ -299,15 +268,11 @@ public class ChatBean implements Serializable { | ||
299 | 268 | chatRoom = e.getNewValue().toString(); |
300 | 269 | log.info("chat room changed: " + this.chatRoom); |
301 | 270 | initMsgList(); |
302 | - initLoadLink(); | |
303 | 271 | initMembers(); |
304 | 272 | } |
305 | 273 | |
306 | 274 | @PostConstruct |
307 | 275 | public void postInit() { |
308 | - //log.info("postInit @" + this.hashCode()); | |
309 | - //log.info("PostConstruct userBean: " + userBean); | |
310 | - //log.info("PostConstruct getFlights: " + userBean.getFlights()); | |
311 | 276 | ArrayList<SelectItem> flights = userBean.getFlights(); |
312 | 277 | if (flights != null) { |
313 | 278 | chatRoom = flights.get(0).getValue().toString(); |
@@ -317,9 +282,6 @@ public class ChatBean implements Serializable { | ||
317 | 282 | log.info("get access. init chat list"); |
318 | 283 | //in get access, the chat room is not selected.. |
319 | 284 | initMsgList(); |
320 | - if (loadLink == null) | |
321 | - loadLink = new HtmlCommandLink(); | |
322 | - initLoadLink(); | |
323 | 285 | initMembers(); |
324 | 286 | } |
325 | 287 | } |
@@ -59,6 +59,12 @@ | ||
59 | 59 | if (data.status == "complete") { |
60 | 60 | var msgList = document.getElementById("chatForm:msgList"); |
61 | 61 | var messages = atmosphere.util.parseJSON(data.responseText); |
62 | + | |
63 | + if (messages == null) { | |
64 | + data.source.text = 'no more old message'; | |
65 | + $('#chatForm\\:msgList\\:loadOldMsg').removeAttr("href"); | |
66 | + return; | |
67 | + } | |
62 | 68 | //console.log(messages); |
63 | 69 | for (var i = 0; i < messages.length; i++) { |
64 | 70 | //row #2 = the first table item. (#0,1 is header element.) |
@@ -213,7 +219,7 @@ $(function () { | ||
213 | 219 | rendered="#{not empty chatBean.msgList}" border="0"> |
214 | 220 | |
215 | 221 | <f:facet name="header"> |
216 | - <h:commandLink binding="#{chatBean.loadLink}" action="#{chatBean.loadOldMsg}" > | |
222 | + <h:commandLink id= "loadOldMsg" value="load old messages" action="#{chatBean.loadOldMsg}"> | |
217 | 223 | <!-- f:ajax render="msgList" / --> |
218 | 224 | <f:ajax onevent="handleLoadOld" /> |
219 | 225 | </h:commandLink> |