You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by mm...@apache.org on 2006/03/07 21:08:22 UTC

svn commit: r383993 - /myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/util/RestoreStateUtils.java

Author: mmarinschek
Date: Tue Mar  7 12:08:20 2006
New Revision: 383993

URL: http://svn.apache.org/viewcvs?rev=383993&view=rev
Log:
revised the hack for component bindings to work with the new shared-package structure as well (via reflection). This is a work-around for a spec bug and will be fixed in JSF2.0!

Modified:
    myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/util/RestoreStateUtils.java

Modified: myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/util/RestoreStateUtils.java
URL: http://svn.apache.org/viewcvs/myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/util/RestoreStateUtils.java?rev=383993&r1=383992&r2=383993&view=diff
==============================================================================
--- myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/util/RestoreStateUtils.java (original)
+++ myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/util/RestoreStateUtils.java Tue Mar  7 12:08:20 2006
@@ -1,12 +1,17 @@
 package org.apache.myfaces.shared.util;
 
 import org.apache.myfaces.shared.component.BindingAware;
+import org.apache.commons.digester.Digester;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 import javax.faces.context.FacesContext;
 import javax.faces.component.UIComponent;
 import javax.faces.component.UIInput;
 import javax.faces.el.ValueBinding;
 import java.util.Iterator;
+import java.lang.reflect.Method;
+import java.lang.reflect.InvocationTargetException;
 
 /**
  * @author Martin Marinschek (latest modification by $Author: grantsmith $)
@@ -14,6 +19,8 @@
  */
 public class RestoreStateUtils
 {
+    private static Log log = LogFactory.getLog(RestoreStateUtils.class);
+
     /**
      * Walk the component tree, executing any component-bindings to reattach
      * components to their backing beans. Also, any UIInput component is
@@ -29,17 +36,27 @@
      * to allow them to define their interest in handling children bindings themselves.
      */
     public static void recursivelyHandleComponentReferencesAndSetValid(FacesContext facesContext,
-                                                                        UIComponent parent)
+                                                                       UIComponent parent)
     {
         recursivelyHandleComponentReferencesAndSetValid(facesContext, parent, false);
     }
 
     public static void recursivelyHandleComponentReferencesAndSetValid(FacesContext facesContext,
-                                                                        UIComponent parent, boolean forceHandle)
+                                                                       UIComponent parent, boolean forceHandle)
     {
-        if(parent instanceof BindingAware && !forceHandle)
+        Method handleBindingsMethod = getBindingMethod(parent);
+
+        if(handleBindingsMethod!=null && !forceHandle)
         {
-            ((BindingAware) parent).handleBindings();
+            try
+            {
+                handleBindingsMethod.invoke(parent,new Object[]{});
+            }
+            catch (Throwable th)
+            {
+                log.error("Exception while invoking handleBindings on component with client-id:"
+                        +parent.getClientId(facesContext),th);
+            }
         }
         else
         {
@@ -61,5 +78,34 @@
                 recursivelyHandleComponentReferencesAndSetValid(facesContext, component);
             }
         }
+    }
+
+    /**This is all a hack to work around a spec-bug which will be fixed in JSF2.0
+     *
+     * @param parent
+     * @return true if this component is bindingAware (e.g. aliasBean)
+     */
+    private static Method getBindingMethod(UIComponent parent)
+    {
+        Class[] clazzes = parent.getClass().getInterfaces();
+
+        for (int i = 0; i < clazzes.length; i++)
+        {
+            Class clazz = clazzes[i];
+
+            if(clazz.getName().indexOf("BindingAware")!=-1)
+            {
+                try
+                {
+                    return  parent.getClass().getMethod("handleBindings",new Class[]{});
+                }
+                catch (NoSuchMethodException e)
+                {
+                    // return
+                }
+            }
+        }
+
+        return null;
     }
 }