myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From embre...@apache.org
Subject svn commit: r1823976 - in /myfaces/core/branches/2.3.x: impl/src/main/java/org/apache/myfaces/config/FacesConfigurator.java shared-public/src/main/java/org/apache/myfaces/shared/util/ClassUtils.java
Date Mon, 12 Feb 2018 14:36:05 GMT
Author: embreijo
Date: Mon Feb 12 14:36:05 2018
New Revision: 1823976

URL: http://svn.apache.org/viewvc?rev=1823976&view=rev
Log:
MYFACES-4198 Injection on custom navigation handlers does not work

Modified:
    myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/config/FacesConfigurator.java
    myfaces/core/branches/2.3.x/shared-public/src/main/java/org/apache/myfaces/shared/util/ClassUtils.java

Modified: myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/config/FacesConfigurator.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/config/FacesConfigurator.java?rev=1823976&r1=1823975&r2=1823976&view=diff
==============================================================================
--- myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/config/FacesConfigurator.java
(original)
+++ myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/config/FacesConfigurator.java
Mon Feb 12 14:36:05 2018
@@ -724,12 +724,18 @@ public class FacesConfigurator
             application.setMessageBundle(dispenser.getMessageBundle());
         }
         
+        // First build the object
         NavigationHandler navigationHandler = ClassUtils.buildApplicationObject(NavigationHandler.class,
-                ConfigurableNavigationHandler.class,
-                BackwardsCompatibleNavigationHandlerWrapper.class,
                 dispenser.getNavigationHandlerIterator(),
                 application.getNavigationHandler());
+        // Invoke inject and post construct
         _callInjectAndPostConstruct(navigationHandler);
+        // Finally wrap the object with the BackwardsCompatibleNavigationHandlerWrapper
+        navigationHandler = ClassUtils.wrapBackwardCompatible(NavigationHandler.class,
+                ConfigurableNavigationHandler.class,
+                BackwardsCompatibleNavigationHandlerWrapper.class,
+                application.getNavigationHandler(),
+                navigationHandler);
         application.setNavigationHandler(navigationHandler);
 
         StateManager stateManager = ClassUtils.buildApplicationObject(StateManager.class,

Modified: myfaces/core/branches/2.3.x/shared-public/src/main/java/org/apache/myfaces/shared/util/ClassUtils.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.3.x/shared-public/src/main/java/org/apache/myfaces/shared/util/ClassUtils.java?rev=1823976&r1=1823975&r2=1823976&view=diff
==============================================================================
--- myfaces/core/branches/2.3.x/shared-public/src/main/java/org/apache/myfaces/shared/util/ClassUtils.java
(original)
+++ myfaces/core/branches/2.3.x/shared-public/src/main/java/org/apache/myfaces/shared/util/ClassUtils.java
Mon Feb 12 14:36:05 2018
@@ -629,45 +629,70 @@ public final class ClassUtils
                     newCurrent = (T) ClassUtils.newInstance(implClass);
                 }
                 
-                // now we have a new current object (newCurrent)
-                // --> find out if it is assignable from extendedInterfaceClass
-                // and if not, wrap it in a backwards compatible wrapper (if available)
-                if (extendedInterfaceWrapperClass != null
-                        && !extendedInterfaceClass.isAssignableFrom(newCurrent.getClass()))
-                {
-                    try
-                    {
-                        Constructor<? extends T> wrapperConstructor
-                                = extendedInterfaceWrapperClass.getConstructor(
-                                        new Class[] {interfaceClass, extendedInterfaceClass});
-                        newCurrent = wrapperConstructor.newInstance(new Object[] {newCurrent,
current});
-                    }
-                    catch (NoSuchMethodException e)
-                    {
-                        log.log(Level.SEVERE, e.getMessage(), e);
-                        throw new FacesException(e);
-                    }
-                    catch (InstantiationException e)
-                    {
-                        log.log(Level.SEVERE, e.getMessage(), e);
-                        throw new FacesException(e);
-                    }
-                    catch (IllegalAccessException e)
-                    {
-                        log.log(Level.SEVERE, e.getMessage(), e);
-                        throw new FacesException(e);
-                    }
-                    catch (InvocationTargetException e)
-                    {
-                        log.log(Level.SEVERE, e.getMessage(), e);
-                        throw new FacesException(e);
-                    }
-                }
-                
-                current = newCurrent;
+                current = wrapBackwardCompatible(interfaceClass, extendedInterfaceClass,

+                                                    extendedInterfaceWrapperClass, current,
newCurrent);
             }
         }
 
         return current;
     }
+    
+    
+    /**
+     * Wrap an object using a backwards compatible wrapper if available
+     * @param interfaceClass The class from which the implementation has to inherit from.
+     * @param extendedInterfaceClass A subclass of interfaceClass which specifies a more
+     *                               detailed implementation.
+     * @param extendedInterfaceWrapperClass A wrapper class for the case that you have an
ApplicationObject
+     *                                      which only implements the interfaceClass but
not the 
+     *                                      extendedInterfaceClass.
+     * @param defaultObject The default implementation for the given ApplicationObject.
+     * @param newCurrent The new current object
+     * @return
+     */
+    public static <T> T wrapBackwardCompatible(Class<T> interfaceClass, Class<?
extends T> extendedInterfaceClass,
+                                               Class<? extends T> extendedInterfaceWrapperClass,

+                                               T defaultObject, T newCurrent)
+    {
+        
+        T current = newCurrent;
+        
+        // now we have a new current object (newCurrent)
+        // --> find out if it is assignable from extendedInterfaceClass
+        // and if not, wrap it in a backwards compatible wrapper (if available)
+        if (extendedInterfaceWrapperClass != null
+                && !extendedInterfaceClass.isAssignableFrom(current.getClass()))
+        {
+            try
+            {
+                Constructor<? extends T> wrapperConstructor
+                        = extendedInterfaceWrapperClass.getConstructor(
+                                new Class[] {interfaceClass, extendedInterfaceClass});
+                current = wrapperConstructor.newInstance(new Object[] {newCurrent, defaultObject});
+            }
+            catch (NoSuchMethodException e)
+            {
+                log.log(Level.SEVERE, e.getMessage(), e);
+                throw new FacesException(e);
+            }
+            catch (InstantiationException e)
+            {
+                log.log(Level.SEVERE, e.getMessage(), e);
+                throw new FacesException(e);
+            }
+            catch (IllegalAccessException e)
+            {
+                log.log(Level.SEVERE, e.getMessage(), e);
+                throw new FacesException(e);
+            }
+            catch (InvocationTargetException e)
+            {
+                log.log(Level.SEVERE, e.getMessage(), e);
+                throw new FacesException(e);
+            }
+        }
+        
+        return current;
+    }
+    
 }



Mime
View raw message