• 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

Revision576daed25801b1f0536b9c6391e7fdd6eed62b3f (tree)
Time2014-02-05 15:42:46
Authorastoria-d <astoria-d@mail...>
Commiterastoria-d

Log Message

clean up

Change Summary

Incremental Difference

--- a/WEB-INF/classes/motoSample/ChatBean.java
+++ b/WEB-INF/classes/motoSample/ChatBean.java
@@ -46,7 +46,7 @@ public class ChatBean implements Serializable {
4646 //inject user bean
4747 @ManagedProperty("#{userBean}")
4848 private UserBean userBean;
49-
49+ //all login members list
5050 @ManagedProperty("#{loginMemberBean}")
5151 private LoginMemberBean loginMemberBean;
5252
@@ -54,8 +54,9 @@ public class ChatBean implements Serializable {
5454 private String chatRoom;
5555 private int oldestChatId;
5656 private ArrayList<ChatMessage> msgList;
57+
58+ //members that are associated with this chat room
5759 private MemberList memList;
58- private HtmlCommandLink loadLink;
5960
6061 public final static int LIST_LOAD_SIZE = 10;
6162
@@ -72,14 +73,6 @@ public class ChatBean implements Serializable {
7273 public String getChatRoom() {
7374 return chatRoom;
7475 }
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- }
8376 public MemberList getMemList(){
8477 return memList;
8578 }
@@ -156,17 +149,6 @@ public class ChatBean implements Serializable {
156149 }
157150
158151 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);
170152 return msgList;
171153 }
172154
@@ -181,12 +163,6 @@ public class ChatBean implements Serializable {
181163 if (msg.equals(""))
182164 return;
183165
184- /*
185- log.info("user = " + userBean.getUid());
186- log.info("chat room = " + chatRoom);
187- log.info("date = " + df.format(d));
188- */
189-
190166 String dt = formatDate();
191167 try {
192168 Connection conn = Resources.getConnection();
@@ -256,21 +232,19 @@ public class ChatBean implements Serializable {
256232 rs.close();
257233 conn.close();
258234
235+ ExternalContext externalContext = context.getExternalContext();
236+ externalContext.setResponseContentType("application/json");
237+ externalContext.setResponseCharacterEncoding("UTF-8");
259238 if (load_cnt == 0) {
260239 log.info("no more old msg...");
261- loadLink.setDisabled(true);
262- loadLink.setValue("no more old messages....");
263240 }
264241 else {
265242 //output json object.
266- ExternalContext externalContext = context.getExternalContext();
267- externalContext.setResponseContentType("application/json");
268- externalContext.setResponseCharacterEncoding("UTF-8");
269243 ObjectMapper mapper = new ObjectMapper();
270244 String json = mapper.writeValueAsString(retList);
271245 externalContext.getResponseOutputWriter().write(json);
272- context.responseComplete();
273246 }
247+ context.responseComplete();
274248 }
275249 catch (SQLException se) {
276250 log.severe("sql err!!!");
@@ -281,11 +255,6 @@ public class ChatBean implements Serializable {
281255
282256 }
283257
284- void initLoadLink() {
285- loadLink.setDisabled(false);
286- loadLink.setValue("load old messages...");
287- }
288-
289258 void initMembers() {
290259 if (memList == null)
291260 memList = new MemberList();
@@ -299,15 +268,11 @@ public class ChatBean implements Serializable {
299268 chatRoom = e.getNewValue().toString();
300269 log.info("chat room changed: " + this.chatRoom);
301270 initMsgList();
302- initLoadLink();
303271 initMembers();
304272 }
305273
306274 @PostConstruct
307275 public void postInit() {
308- //log.info("postInit @" + this.hashCode());
309- //log.info("PostConstruct userBean: " + userBean);
310- //log.info("PostConstruct getFlights: " + userBean.getFlights());
311276 ArrayList<SelectItem> flights = userBean.getFlights();
312277 if (flights != null) {
313278 chatRoom = flights.get(0).getValue().toString();
@@ -317,9 +282,6 @@ public class ChatBean implements Serializable {
317282 log.info("get access. init chat list");
318283 //in get access, the chat room is not selected..
319284 initMsgList();
320- if (loadLink == null)
321- loadLink = new HtmlCommandLink();
322- initLoadLink();
323285 initMembers();
324286 }
325287 }
--- a/secured/chat.xhtml
+++ b/secured/chat.xhtml
@@ -59,6 +59,12 @@
5959 if (data.status == "complete") {
6060 var msgList = document.getElementById("chatForm:msgList");
6161 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+ }
6268 //console.log(messages);
6369 for (var i = 0; i < messages.length; i++) {
6470 //row #2 = the first table item. (#0,1 is header element.)
@@ -213,7 +219,7 @@ $(function () {
213219 rendered="#{not empty chatBean.msgList}" border="0">
214220
215221 <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}">
217223 <!-- f:ajax render="msgList" / -->
218224 <f:ajax onevent="handleLoadOld" />
219225 </h:commandLink>