You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lu...@apache.org on 2013/02/08 00:41:09 UTC

svn commit: r1443787 - in /myfaces/core/branches/2.2.x/api/src/main/java/javax/faces: component/UIViewAction.java view/ViewMetadata.java

Author: lu4242
Date: Thu Feb  7 23:41:09 2013
New Revision: 1443787

URL: http://svn.apache.org/r1443787
Log:
MYFACES-3674 Implement f:viewAction 

Modified:
    myfaces/core/branches/2.2.x/api/src/main/java/javax/faces/component/UIViewAction.java
    myfaces/core/branches/2.2.x/api/src/main/java/javax/faces/view/ViewMetadata.java

Modified: myfaces/core/branches/2.2.x/api/src/main/java/javax/faces/component/UIViewAction.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.2.x/api/src/main/java/javax/faces/component/UIViewAction.java?rev=1443787&r1=1443786&r2=1443787&view=diff
==============================================================================
--- myfaces/core/branches/2.2.x/api/src/main/java/javax/faces/component/UIViewAction.java (original)
+++ myfaces/core/branches/2.2.x/api/src/main/java/javax/faces/component/UIViewAction.java Thu Feb  7 23:41:09 2013
@@ -111,13 +111,12 @@ public class UIViewAction extends UIComp
                     {
                         wrappedFacesContext.setWrapperAsCurrentFacesContext();
 
-                        /* Note f:viewAction does not have actionListener property defined.
                         MethodBinding mb = getActionListener();
                         if (mb != null)
                         {
                             mb.invoke(context, new Object[]
                             { event });
-                        }*/
+                        }
 
                         if (defaultActionListener != null)
                         {
@@ -280,18 +279,16 @@ public class UIViewAction extends UIComp
         getStateHelper().put(PropertyKeys.actionExpression, actionExpression);
     }
 
-    //@JSFProperty(stateHolder=true, returnSignature = "void", methodSignature = "javax.faces.event.ActionEvent")
+    @JSFProperty(stateHolder=true, returnSignature = "void", methodSignature = "javax.faces.event.ActionEvent")
     public MethodBinding getActionListener()
     {
         return (MethodBinding) getStateHelper().eval(PropertyKeys.actionListener);
-        // Note f:viewAction does not have actionListener property defined.
-        //throw new UnsupportedOperationException();
     }
 
     /**
      * @deprecated
      */
-    //@JSFProperty(returnSignature="void",methodSignature="javax.faces.event.ActionEvent")
+    @JSFProperty(returnSignature="void",methodSignature="javax.faces.event.ActionEvent")
     public void setActionListener(MethodBinding actionListener)
     {
         getStateHelper().put(PropertyKeys.actionListener, actionListener);

Modified: myfaces/core/branches/2.2.x/api/src/main/java/javax/faces/view/ViewMetadata.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.2.x/api/src/main/java/javax/faces/view/ViewMetadata.java?rev=1443787&r1=1443786&r2=1443787&view=diff
==============================================================================
--- myfaces/core/branches/2.2.x/api/src/main/java/javax/faces/view/ViewMetadata.java (original)
+++ myfaces/core/branches/2.2.x/api/src/main/java/javax/faces/view/ViewMetadata.java Thu Feb  7 23:41:09 2013
@@ -24,6 +24,7 @@ import java.util.Iterator;
 import java.util.LinkedList;
 
 import javax.faces.component.UIComponent;
+import javax.faces.component.UIViewAction;
 import javax.faces.component.UIViewParameter;
 import javax.faces.component.UIViewRoot;
 import javax.faces.context.FacesContext;
@@ -86,4 +87,67 @@ public abstract class ViewMetadata
             return Collections.unmodifiableCollection (result);
         }
     }
+    
+    /**
+     * @since 2.2
+     * @param root
+     * @return 
+     */
+    public static Collection<UIViewAction> getViewActions(UIViewRoot root)
+    {
+        LinkedList<UIViewAction> result = null;
+        UIComponent metadataFacet = root.getFacet (UIViewRoot.METADATA_FACET_NAME);
+        Iterator<UIComponent> children;
+        
+        if (metadataFacet == null)
+        {
+             // No metadata, so return an empty collection.
+             
+             return Collections.emptyList();
+        }
+        
+        // Iterate over all the children, keep only the view parameters.
+        
+        if (metadataFacet.getChildCount() > 0)
+        {
+            children = metadataFacet.getChildren().iterator();
+            
+            while (children.hasNext())
+            {
+                 UIComponent component = children.next();
+                 
+                 if (result == null)
+                 {
+                     result = new LinkedList<UIViewAction>();
+                 }
+                 
+                 if (component instanceof UIViewAction)
+                 {
+                      result.add ((UIViewAction) component);
+                 }
+            }
+        }
+        
+        // TODO: does this need to be immutable?  Spec does not indicate either
+        // way.
+        if (result == null)
+        {
+            return Collections.emptyList();
+        }
+        else
+        {
+            return Collections.unmodifiableCollection (result);
+        }
+    }
+    
+    /**
+     * @since 2.2
+     * @param root
+     * @return 
+     */
+    public static boolean hasMetadata(UIViewRoot root)
+    {
+        UIComponent metadataFacet = root.getFacet(UIViewRoot.METADATA_FACET_NAME);
+        return metadataFacet != null ? metadataFacet.getChildCount() > 0 : false;
+    }
 }