empire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From doeb...@apache.org
Subject svn commit: r1379992 - in /empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2: app/FacesApplication.java app/FacesUtils.java pages/Page.java pages/PagePhaseListener.java
Date Sun, 02 Sep 2012 15:09:45 GMT
Author: doebele
Date: Sun Sep  2 15:09:44 2012
New Revision: 1379992

URL: http://svn.apache.org/viewvc?rev=1379992&view=rev
Log:
EMPIREDB-169
Manages a PageResourceMap on the session

Modified:
    empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/FacesApplication.java
    empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/FacesUtils.java
    empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pages/Page.java
    empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pages/PagePhaseListener.java

Modified: empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/FacesApplication.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/FacesApplication.java?rev=1379992&r1=1379991&r2=1379992&view=diff
==============================================================================
--- empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/FacesApplication.java
(original)
+++ empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/FacesApplication.java
Sun Sep  2 15:09:44 2012
@@ -35,7 +35,6 @@ import javax.faces.context.FacesContext;
 import javax.servlet.ServletContext;
 import javax.sql.DataSource;
 
-import org.apache.empire.commons.ObjectUtils;
 import org.apache.empire.commons.StringUtils;
 import org.apache.empire.data.DataType;
 import org.apache.empire.db.DBDatabase;
@@ -93,6 +92,11 @@ public abstract class FacesApplication e
     public void onChangeView(final FacesContext fc, String viewId)
     {
         // allow custom view change logic
+
+        // clear page resources
+        Map<String, Object> sm = FacesUtils.getSessionMap(fc);
+        if (sm!=null)
+            sm.remove(FacesUtils.PAGE_RESOURCE_MAP_ATTRIBUTE);
     }
 
     public void addJavascriptCall(final FacesContext fc, String function)

Modified: empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/FacesUtils.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/FacesUtils.java?rev=1379992&r1=1379991&r2=1379992&view=diff
==============================================================================
--- empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/FacesUtils.java
(original)
+++ empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/FacesUtils.java
Sun Sep  2 15:09:44 2012
@@ -21,6 +21,7 @@ package org.apache.empire.jsf2.app;
 import java.io.File;
 import java.io.IOException;
 import java.sql.Connection;
+import java.util.HashMap;
 import java.util.Map;
 
 import javax.el.ELContext;
@@ -59,8 +60,20 @@ public class FacesUtils
         return FacesContext.getCurrentInstance();
     }
 
+    /* Session */
+    
+    public static Map<String, Object> getSessionMap(final FacesContext fc)
+    {
+        return fc.getExternalContext().getSessionMap();
+    }
+    
     /* Request */
 
+    public static Map<String, Object> getRequestMap(final FacesContext fc)
+    {
+        return fc.getExternalContext().getRequestMap();
+    }
+    
     public static HttpServletRequest getHttpRequest(final FacesContext fc)
     {
         return (HttpServletRequest) fc.getExternalContext().getRequest();
@@ -152,6 +165,21 @@ public class FacesUtils
         }
         return (ParameterMap)pm;
     }
+
+    /* PageResource-map */
+    public static final String PAGE_RESOURCE_MAP_ATTRIBUTE = "pageResources"; /** use el-expression:
#{pageResources.xxx} **/
+    
+    @SuppressWarnings("unchecked")
+    public static Map<String, Object> getPageResourceMap(final FacesContext fc)
+    {
+        Map<String, Object> sm = fc.getExternalContext().getSessionMap();
+        Map<String, Object> rm = (Map<String, Object>)sm.get(PAGE_RESOURCE_MAP_ATTRIBUTE);
+        if (rm==null)
+        {   rm = new HashMap<String, Object>();
+            sm.put(PAGE_RESOURCE_MAP_ATTRIBUTE, rm);
+        }
+        return rm;
+    }
     
     /* Managed Beans */
     

Modified: empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pages/Page.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pages/Page.java?rev=1379992&r1=1379991&r2=1379992&view=diff
==============================================================================
--- empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pages/Page.java (original)
+++ empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pages/Page.java Sun
Sep  2 15:09:44 2012
@@ -380,6 +380,37 @@ public abstract class Page implements Se
         app.addJavascriptCall(fc, function);
     }
     
+    /* Page Resources */
+    
+    /**
+     * Adds an object required for resource handling, to the page resource map.
+     * <pre>
+     * Since resource requests are not attached to a view, they cannot access page properties
via expression language like this
+     *    #{page.someProperty}
+     * Instead, the page should add properties that are required to the "pageResources"-map.
This map is held on the session, and cleared when the page changes.
+     * In order to access such page resources via expression language use
+     *    #{pageResources.someProperty}
+     * </pre>   
+     * @param name the name of the resource
+     * @param resource the resource
+     */
+    public void addPageResource(String name, Object resource)
+    {
+        Map<String, Object> prm = FacesUtils.getPageResourceMap(FacesUtils.getContext());
+        prm.put(name, this);
+    }
+    
+    /**
+     * Returns the page resource object previously added by addPageResource(...)
+     * @param name the name of the resource
+     * @return resource the resource
+     */
+    public Object getPageResource(String name)
+    {
+        Map<String, Object> prm = FacesUtils.getPageResourceMap(FacesUtils.getContext());
+        return prm.get(name);
+    }
+    
     /* Default Init Method */
     public void doInit()
     {

Modified: empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pages/PagePhaseListener.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pages/PagePhaseListener.java?rev=1379992&r1=1379991&r2=1379992&view=diff
==============================================================================
--- empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pages/PagePhaseListener.java
(original)
+++ empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pages/PagePhaseListener.java
Sun Sep  2 15:09:44 2012
@@ -271,8 +271,11 @@ public class PagePhaseListener implement
     {
         if (pe.getPhaseId() != PhaseId.RENDER_RESPONSE)
             return;
-        // Check Page Bean
+        // Get the view
         UIViewRoot vr = pe.getFacesContext().getViewRoot();
+        if (vr==null)
+            return;
+        // Check Page Bean
         Map<String, Object> viewMap = vr.getViewMap();
         Page pageBean = (Page) viewMap.get("page");
         if (pageBean != null && !pageBean.isInitialized())



Mime
View raw message