myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lu4...@apache.org
Subject svn commit: r808696 - in /myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets: AbstractFaceletContext.java impl/DefaultFaceletContext.java
Date Fri, 28 Aug 2009 00:45:33 GMT
Author: lu4242
Date: Fri Aug 28 00:45:32 2009
New Revision: 808696

URL: http://svn.apache.org/viewvc?rev=808696&view=rev
Log:
MYFACES-2310 Implement Composite Component feature (add stack for composite components, useful
implementing  	 MYFACES-2320 and MYFACES-2317)

Modified:
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/AbstractFaceletContext.java
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/impl/DefaultFaceletContext.java

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/AbstractFaceletContext.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/AbstractFaceletContext.java?rev=808696&r1=808695&r2=808696&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/AbstractFaceletContext.java
(original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/AbstractFaceletContext.java
Fri Aug 28 00:45:32 2009
@@ -19,14 +19,19 @@
 package org.apache.myfaces.view.facelets;
 
 import java.io.IOException;
+import java.util.ArrayDeque;
+import java.util.Deque;
+import java.util.Map;
 
 import javax.el.ELException;
 import javax.faces.FacesException;
 import javax.faces.application.Resource;
 import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
 import javax.faces.view.facelets.FaceletContext;
 import javax.faces.view.facelets.FaceletException;
 
+
 /**
  * This class contains methods that belongs to original FaceletContext shipped in
  * facelets code before 2.0, but does not take part from api, so are considered 
@@ -43,6 +48,8 @@
  */
 public abstract class AbstractFaceletContext extends FaceletContext
 {
+    public final static String COMPOSITE_COMPONENT_STACK = "org.apache.myfaces.view.facelets.COMPOSITE_COMPONENT_STACK";
+
     /**
      * Push the passed TemplateClient onto the stack for Definition Resolution
      * @param client
@@ -91,4 +98,22 @@
      */
     public abstract void applyCompositeComponent(UIComponent parent, Resource resource)
             throws IOException, FaceletException, FacesException, ELException;
+
+    /**
+     * Return the composite component being applied on the current facelet. 
+     * 
+     * Note this is different to UIComponent.getCurrentCompositeComponent, because a composite
+     * component is added to the stack each time a composite:implementation tag handler is
applied.
+     * 
+     * This could be used by InsertChildrenHandler and InsertFacetHandler to retrieve the
current
+     * composite component to be applied.
+     * 
+     * @param facesContext
+     * @return
+     */
+    public abstract UIComponent getCompositeComponentFromStack();
+
+    public abstract void pushCompositeComponentToStack(UIComponent parent);
+
+    public abstract void popCompositeComponentToStack();
 }

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/impl/DefaultFaceletContext.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/impl/DefaultFaceletContext.java?rev=808696&r1=808695&r2=808696&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/impl/DefaultFaceletContext.java
(original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/impl/DefaultFaceletContext.java
Fri Aug 28 00:45:32 2009
@@ -20,7 +20,9 @@
 
 import java.io.IOException;
 import java.net.URL;
+import java.util.ArrayDeque;
 import java.util.ArrayList;
+import java.util.Deque;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
@@ -442,4 +444,44 @@
     {
         _facelet.applyCompositeComponent(this, parent, resource);
     }
+    
+    @Override
+    public UIComponent getCompositeComponentFromStack()
+    {
+        Map<Object, Object> attributes = getFacesContext().getAttributes();   
+        
+        Deque<UIComponent> componentStack = (Deque<UIComponent>) attributes.get(AbstractFaceletContext.COMPOSITE_COMPONENT_STACK);
+        if(componentStack != null && !componentStack.isEmpty())
+        {
+            return componentStack.peek();
+        }
+        return null;
+    }
+
+    @Override
+    public void pushCompositeComponentToStack(UIComponent parent)    {
+        Map<Object, Object> attributes = getFacesContext().getAttributes();   
+        
+        Deque<UIComponent> componentStack = (Deque<UIComponent>) attributes.get(AbstractFaceletContext.COMPOSITE_COMPONENT_STACK);
+        if(componentStack == null)
+        {
+            componentStack = new ArrayDeque<UIComponent>();
+            attributes.put(AbstractFaceletContext.COMPOSITE_COMPONENT_STACK, componentStack);
+        }
+        
+        componentStack.push(parent);
+    }
+
+    @Override
+    public void popCompositeComponentToStack()
+    {
+        Map<Object, Object> contextAttributes = getFacesContext().getAttributes();
  
+        
+        Deque<UIComponent> componentStack = (Deque<UIComponent>) contextAttributes.get(AbstractFaceletContext.COMPOSITE_COMPONENT_STACK);
+        if(componentStack != null && !componentStack.isEmpty())
+        {
+            componentStack.pop();
+        }
+    }    
+
 }



Mime
View raw message