myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lof...@apache.org
Subject svn commit: r1461724 - in /myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main: java/org/apache/myfaces/tobago/example/demo/info/ webapp/ webapp/WEB-INF/
Date Wed, 27 Mar 2013 17:19:51 GMT
Author: lofwyr
Date: Wed Mar 27 17:19:50 2013
New Revision: 1461724

URL: http://svn.apache.org/r1461724
Log:
Using CDI for the ActivityList

Removed:
    myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/info/ActivityServletContextListener.java
Modified:
    myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/info/Activity.java
    myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/info/ActivityList.java
    myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/info/ActivityPhaseListener.java
    myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/info/ActivitySessionListener.java
    myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/WEB-INF/faces-config.xml
    myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/server-info.xhtml

Modified: myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/info/Activity.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/info/Activity.java?rev=1461724&r1=1461723&r2=1461724&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/info/Activity.java
(original)
+++ myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/info/Activity.java
Wed Mar 27 17:19:50 2013
@@ -20,9 +20,10 @@
 package org.apache.myfaces.tobago.example.demo.info;
 
 import javax.servlet.http.HttpSession;
+import java.io.Serializable;
 import java.util.Date;
 
-public class Activity {
+public class Activity implements Serializable {
 
   private String sessionId;
 
@@ -37,11 +38,11 @@ public class Activity {
     this.creationDate = new Date(session.getCreationTime());
   }
 
-  public void jsfRequest() {
+  public void executeJsfRequest() {
     jsfRequest++;
   }
 
-  public void ajaxRequest() {
+  public void executeAjaxRequest() {
       ajaxRequest++;
   }
 

Modified: myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/info/ActivityList.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/info/ActivityList.java?rev=1461724&r1=1461723&r2=1461724&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/info/ActivityList.java
(original)
+++ myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/info/ActivityList.java
Wed Mar 27 17:19:50 2013
@@ -22,18 +22,23 @@ package org.apache.myfaces.tobago.exampl
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Named;
+import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 
-public class ActivityList {
+@Named
+@ApplicationScoped
+public class ActivityList implements Serializable {
 
   private static final Logger LOG = LoggerFactory.getLogger(ActivityList.class);
 
-  public static final String NAME = "activities";
-
+  // XXX using the session id as key is not good for applications with login, because the
container should change
+  // XXX the session id while the login process.
   private Map<String, Activity> data = new ConcurrentHashMap<String, Activity>();
 
   public void add(Activity activity) {
@@ -43,7 +48,7 @@ public class ActivityList {
 
   public void remove(String sessionId) {
     LOG.info("Removing session id: " + sessionId);
-    final Activity activity = data.remove(sessionId);
+    data.remove(sessionId);
   }
 
   public List<Activity> getValues() {
@@ -53,11 +58,11 @@ public class ActivityList {
     return result;
   }
 
-  public void jsfRequest(String sessionId) {
-    data.get(sessionId).jsfRequest();
+  public void executeJsfRequest(String sessionId) {
+    data.get(sessionId).executeJsfRequest();
   }
 
-  public void ajaxRequest(String sessionId) {
-    data.get(sessionId).ajaxRequest();
+  public void executeAjaxRequest(String sessionId) {
+    data.get(sessionId).executeAjaxRequest();
   }
 }

Modified: myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/info/ActivityPhaseListener.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/info/ActivityPhaseListener.java?rev=1461724&r1=1461723&r2=1461724&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/info/ActivityPhaseListener.java
(original)
+++ myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/info/ActivityPhaseListener.java
Wed Mar 27 17:19:50 2013
@@ -19,36 +19,41 @@
 
 package org.apache.myfaces.tobago.example.demo.info;
 
+import org.apache.myfaces.extensions.cdi.core.api.Advanced;
+import org.apache.myfaces.extensions.cdi.jsf.api.listener.phase.JsfPhaseListener;
 import org.apache.myfaces.tobago.ajax.AjaxUtils;
-import org.apache.myfaces.tobago.util.VariableResolverUtils;
 
 import javax.faces.context.FacesContext;
 import javax.faces.event.PhaseEvent;
 import javax.faces.event.PhaseId;
 import javax.faces.event.PhaseListener;
+import javax.inject.Inject;
 import javax.servlet.http.HttpSession;
 
+@Advanced
+@JsfPhaseListener
 public class ActivityPhaseListener implements PhaseListener {
 
-  public ActivityPhaseListener() {
-  }
+  @Inject
+  private ActivityList activityList;
 
-  public void afterPhase(PhaseEvent event) {
+  public ActivityPhaseListener() {
   }
 
   public void beforePhase(PhaseEvent event) {
     final FacesContext facesContext = event.getFacesContext();
-    final ActivityList activityList
-        = (ActivityList) VariableResolverUtils.resolveVariable(facesContext, ActivityList.NAME);
     String sessionId = ((HttpSession) facesContext.getExternalContext().getSession(true)).getId();
 
     if (AjaxUtils.isAjaxRequest(facesContext)) {
-      activityList.ajaxRequest(sessionId);
+      activityList.executeAjaxRequest(sessionId);
     } else {
-      activityList.jsfRequest(sessionId);
+      activityList.executeJsfRequest(sessionId);
     }
   }
 
+  public void afterPhase(PhaseEvent event) {
+  }
+
   public PhaseId getPhaseId() {
     return PhaseId.RENDER_RESPONSE;
   }

Modified: myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/info/ActivitySessionListener.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/info/ActivitySessionListener.java?rev=1461724&r1=1461723&r2=1461724&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/info/ActivitySessionListener.java
(original)
+++ myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/info/ActivitySessionListener.java
Wed Mar 27 17:19:50 2013
@@ -19,26 +19,25 @@
 
 package org.apache.myfaces.tobago.example.demo.info;
 
-import javax.servlet.ServletContext;
+import org.apache.myfaces.extensions.cdi.core.api.provider.BeanManagerProvider;
+
 import javax.servlet.http.HttpSession;
 import javax.servlet.http.HttpSessionEvent;
 import javax.servlet.http.HttpSessionListener;
 
 public class ActivitySessionListener implements HttpSessionListener {
 
-  private static final String SESSION_MAP = ActivitySessionListener.class.getName() + ".SESSION_MAP";
-
   public void sessionCreated(HttpSessionEvent event) {
     final HttpSession session = event.getSession();
-    final ServletContext application = session.getServletContext();
-    final ActivityList activityList = (ActivityList) application.getAttribute(ActivityList.NAME);
+    final ActivityList activityList = BeanManagerProvider.getInstance().getContextualReference(ActivityList.class);
+
     activityList.add(new Activity(session));
   }
 
   public void sessionDestroyed(HttpSessionEvent event) {
     final HttpSession session = event.getSession();
-    final ServletContext application = session.getServletContext();
-    final ActivityList activityList = (ActivityList) application.getAttribute(ActivityList.NAME);
+    final ActivityList activityList = BeanManagerProvider.getInstance().getContextualReference(ActivityList.class);
+
     activityList.remove(session.getId());
   }
 }

Modified: myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/WEB-INF/faces-config.xml
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/WEB-INF/faces-config.xml?rev=1461724&r1=1461723&r2=1461724&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/WEB-INF/faces-config.xml
(original)
+++ myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/WEB-INF/faces-config.xml
Wed Mar 27 17:19:50 2013
@@ -62,9 +62,6 @@
       org.apache.myfaces.tobago.example.demo.SynchronizeNavigationPhaseListener
     </phase-listener>
     <phase-listener>
-      org.apache.myfaces.tobago.example.demo.info.ActivityPhaseListener
-    </phase-listener>
-    <phase-listener>
       org.apache.myfaces.tobago.util.DebugPhaseListener
     </phase-listener>
   </lifecycle>

Modified: myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/server-info.xhtml
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/server-info.xhtml?rev=1461724&r1=1461723&r2=1461724&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/server-info.xhtml
(original)
+++ myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/server-info.xhtml
Wed Mar 27 17:19:50 2013
@@ -74,7 +74,7 @@
 
       <tc:label value="Sessions"/>
 
-      <tc:sheet value="#{activities.values}" var="activity"
+      <tc:sheet value="#{activityList.values}" var="activity"
                 showRowRange="left" showPageRange="right" showDirectLinks="center">
         <tc:column label="Session Id">
           <tc:out value="#{activity.sessionId}"/>



Mime
View raw message