myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lu4...@apache.org
Subject svn commit: r1296408 - in /myfaces/core/branches/2.0.x: api/src/main/java/javax/faces/component/behavior/AjaxBehavior.java impl/src/main/java/org/apache/myfaces/renderkit/html/HtmlAjaxBehaviorRenderer.java
Date Fri, 02 Mar 2012 19:43:28 GMT
Author: lu4242
Date: Fri Mar  2 19:43:28 2012
New Revision: 1296408

URL: http://svn.apache.org/viewvc?rev=1296408&view=rev
Log:
MYFACES-3419 AjaxBehavior.isImmediateSet(): information allows an associated client behavior
renderer to fall back on the parent component's immediate status (Thanks to Martin Kočí
for provide this patch)

Modified:
    myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/component/behavior/AjaxBehavior.java
    myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/renderkit/html/HtmlAjaxBehaviorRenderer.java

Modified: myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/component/behavior/AjaxBehavior.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/component/behavior/AjaxBehavior.java?rev=1296408&r1=1296407&r2=1296408&view=diff
==============================================================================
--- myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/component/behavior/AjaxBehavior.java
(original)
+++ myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/component/behavior/AjaxBehavior.java
Fri Mar  2 19:43:28 2012
@@ -137,7 +137,8 @@ public class AjaxBehavior extends Client
     public ValueExpression getValueExpression(String name) 
     {
         //return getValueExpressionMap().get(name);
-        if (name == null) {
+        if (name == null)
+        {
             throw new NullPointerException("name can not be null");
         }
         
@@ -166,13 +167,17 @@ public class AjaxBehavior extends Client
             getValueExpressionMap().put(name, item);
         }
         */
-        if (name == null) {
+        if (name == null)
+        {
             throw new NullPointerException("name");
         }
 
-        if (expression == null) {
+        if (expression == null)
+        {
             getStateHelper().remove(PropertyKeys.bindings, name);
-        } else {
+        }
+        else
+        {
             getStateHelper().put(PropertyKeys.bindings, name, expression);
         }
     }
@@ -203,7 +208,8 @@ public class AjaxBehavior extends Client
 
     public boolean isImmediateSet() 
     {
-        return getStateHelper().eval(ATTR_IMMEDIATE) != null;
+        return (getStateHelper().get(ATTR_IMMEDIATE) != null) ||
+            (getValueExpression(ATTR_IMMEDIATE) != null);
     }
 
     @Override
@@ -233,7 +239,8 @@ public class AjaxBehavior extends Client
         getStateHelper().restoreState(facesContext, values[1]);
     }
 
-    private StateHelper getStateHelper() {
+    private StateHelper getStateHelper()
+    {
         return getStateHelper(true);
     }
 
@@ -243,11 +250,14 @@ public class AjaxBehavior extends Client
      * @param create if true a state helper is created if not already existing
      * @return an implementation of the StateHelper interface or null if none exists and
create is set to false
      */
-    private StateHelper getStateHelper(boolean create) {
-        if(_stateHelper != null) {
+    private StateHelper getStateHelper(boolean create)
+    {
+        if(_stateHelper != null)
+        {
             return _stateHelper;
         }
-        if(create) {
+        if(create)
+        {
             _stateHelper = new _DeltaStateHelper<AjaxBehavior>(this);
         }
         return _stateHelper;
@@ -326,7 +336,8 @@ public class AjaxBehavior extends Client
      * @param stringValue
      * @return
      */
-    private Collection<String> getCollectionFromSpaceSplitString(String stringValue)
{
+    private Collection<String> getCollectionFromSpaceSplitString(String stringValue)
+    {
         //@special handling for @all, @none, @form and @this
         if (stringValue.equals(VAL_FORM)) 
         {

Modified: myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/renderkit/html/HtmlAjaxBehaviorRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/renderkit/html/HtmlAjaxBehaviorRenderer.java?rev=1296408&r1=1296407&r2=1296408&view=diff
==============================================================================
--- myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/renderkit/html/HtmlAjaxBehaviorRenderer.java
(original)
+++ myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/renderkit/html/HtmlAjaxBehaviorRenderer.java
Fri Mar  2 19:43:28 2012
@@ -18,9 +18,6 @@
  */
 package org.apache.myfaces.renderkit.html;
 
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
@@ -28,6 +25,8 @@ import java.util.List;
 import java.util.RandomAccess;
 
 import javax.faces.FacesException;
+import javax.faces.component.ActionSource;
+import javax.faces.component.EditableValueHolder;
 import javax.faces.component.UIComponent;
 import javax.faces.component.UINamingContainer;
 import javax.faces.component.behavior.AjaxBehavior;
@@ -106,8 +105,17 @@ public class HtmlAjaxBehaviorRenderer ex
     private final void dispatchBehaviorEvent(UIComponent component, AjaxBehavior ajaxBehavior)
     {
         AjaxBehaviorEvent event = new AjaxBehaviorEvent(component, ajaxBehavior);
-
-        PhaseId phaseId = ajaxBehavior.isImmediate() || isComponentImmediate(component) ?
+        
+        boolean isImmediate = false;
+        if (ajaxBehavior.isImmediateSet())
+        {
+            isImmediate = ajaxBehavior.isImmediate();
+        }            
+        else
+        {
+            isImmediate = isComponentImmediate(component);
+        }
+        PhaseId phaseId = isImmediate ?
                 PhaseId.APPLY_REQUEST_VALUES :
                 PhaseId.INVOKE_APPLICATION;
 
@@ -119,40 +127,16 @@ public class HtmlAjaxBehaviorRenderer ex
 
     private final boolean isComponentImmediate(UIComponent component)
     {
-        /**
-         * Currently implemented by ActionSource and EditableValueHolder
-         * but we cannot be sure about both interfaces so
-         * lets make introspection calls here
-         */
-        Method immediate = null;
-        try
-        {
-            immediate = component.getClass().getMethod("isImmediate", new Class[]{});
-            //public isImmediate must be present
-            if (Modifier.isPublic(immediate.getModifiers()) ||
-                    immediate.getReturnType().equals(boolean.class) ||
-                    immediate.getReturnType().equals(Boolean.class)) /*autoboxing*/
-            {
-                return (Boolean) immediate.invoke(component, new Object[]{});
-            }
-
-            return false;
-        }
-        catch (NoSuchMethodException e)
-        {
-            //not implemented at all we can return, this is
-            //not really a programmatic exception but we do not have an
-            //hasMethod, and iterating over all methods is way slower
-            return false;
-        }
-        catch (InvocationTargetException e)
+        boolean isImmediate = false;
+        if (component instanceof EditableValueHolder)
         {
-            throw new FacesException(e);
+            isImmediate = ((EditableValueHolder)component).isImmediate();
         }
-        catch (IllegalAccessException e)
+        else if (component instanceof ActionSource)
         {
-            throw new FacesException(e);
+            isImmediate = ((ActionSource)component).isImmediate();
         }
+        return isImmediate;
     }
 
 



Mime
View raw message