You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by an...@apache.org on 2014/06/02 21:46:56 UTC

svn commit: r1599329 - in /tomee/tomee/trunk/examples/myfaces-codi-demo/src/main: java/org/superbiz/myfaces/startup/ExtValLifecycleFactory.java resources/META-INF/persistence.xml webapp/WEB-INF/faces-config.xml

Author: andygumbrecht
Date: Mon Jun  2 19:46:55 2014
New Revision: 1599329

URL: http://svn.apache.org/r1599329
Log:
TOMEE-1155 Patch from Gerhard Petracek applied.

Added:
    tomee/tomee/trunk/examples/myfaces-codi-demo/src/main/java/org/superbiz/myfaces/startup/ExtValLifecycleFactory.java
Modified:
    tomee/tomee/trunk/examples/myfaces-codi-demo/src/main/resources/META-INF/persistence.xml
    tomee/tomee/trunk/examples/myfaces-codi-demo/src/main/webapp/WEB-INF/faces-config.xml

Added: tomee/tomee/trunk/examples/myfaces-codi-demo/src/main/java/org/superbiz/myfaces/startup/ExtValLifecycleFactory.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/examples/myfaces-codi-demo/src/main/java/org/superbiz/myfaces/startup/ExtValLifecycleFactory.java?rev=1599329&view=auto
==============================================================================
--- tomee/tomee/trunk/examples/myfaces-codi-demo/src/main/java/org/superbiz/myfaces/startup/ExtValLifecycleFactory.java (added)
+++ tomee/tomee/trunk/examples/myfaces-codi-demo/src/main/java/org/superbiz/myfaces/startup/ExtValLifecycleFactory.java Mon Jun  2 19:46:55 2014
@@ -0,0 +1,137 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.superbiz.myfaces.startup;
+
+import org.apache.myfaces.extensions.validator.core.DefaultExtValCoreConfiguration;
+import org.apache.myfaces.extensions.validator.core.ExtValCoreConfiguration;
+import org.apache.myfaces.extensions.validator.core.proxy.DefaultProxyHelper;
+import org.apache.myfaces.extensions.validator.core.proxy.ProxyHelper;
+import org.apache.myfaces.extensions.validator.core.startup.AbstractStartupListener;
+
+import javax.faces.FacesException;
+import javax.faces.context.FacesContext;
+import javax.faces.event.PhaseListener;
+import javax.faces.lifecycle.Lifecycle;
+import javax.faces.lifecycle.LifecycleFactory;
+import java.util.Iterator;
+
+//TODO remove it after upgrading to ExtVal r8+
+public class ExtValLifecycleFactory extends LifecycleFactory
+{
+    private final LifecycleFactory wrapped;
+
+    public ExtValLifecycleFactory(LifecycleFactory wrapped)
+    {
+        this.wrapped = wrapped;
+    }
+
+    @Override
+    public void addLifecycle(String lifecycleId, Lifecycle lifecycle)
+    {
+        wrapped.addLifecycle(lifecycleId, lifecycle);
+    }
+
+    @Override
+    public Lifecycle getLifecycle(String lifecycleId)
+    {
+        return new LifecycleWrapper(wrapped.getLifecycle(lifecycleId));
+    }
+
+    @Override
+    public Iterator<String> getLifecycleIds()
+    {
+        return wrapped.getLifecycleIds();
+    }
+
+    @Override
+    public LifecycleFactory getWrapped()
+    {
+        return wrapped;
+    }
+
+    private static class LifecycleWrapper extends Lifecycle
+    {
+        private final Lifecycle wrapped;
+        private static boolean firstPhaseListener = true;
+
+        private LifecycleWrapper(Lifecycle wrapped)
+        {
+            this.wrapped = wrapped;
+        }
+
+        @Override
+        public void addPhaseListener(PhaseListener listener)
+        {
+            if (firstPhaseListener)
+            {
+                //forced order independent of any other config
+                firstPhaseListener = false;
+                wrapped.addPhaseListener(new ExtValStartupListener());
+            }
+            wrapped.addPhaseListener(listener);
+        }
+
+        @Override
+        public void execute(FacesContext context) throws FacesException
+        {
+            wrapped.execute(context);
+        }
+
+        @Override
+        public PhaseListener[] getPhaseListeners()
+        {
+            return wrapped.getPhaseListeners();
+        }
+
+        @Override
+        public void removePhaseListener(PhaseListener listener)
+        {
+            wrapped.removePhaseListener(listener);
+        }
+
+        @Override
+        public void render(FacesContext context) throws FacesException
+        {
+            wrapped.render(context);
+        }
+    }
+
+    public static class ExtValStartupListener extends AbstractStartupListener
+    {
+        @Override
+        protected void init()
+        {
+            ExtValCoreConfiguration.use(new DefaultExtValCoreConfiguration() {
+                @Override
+                public ProxyHelper proxyHelper() {
+                    return new DefaultProxyHelper() {
+                        @Override
+                        public boolean isProxiedClass(Class currentClass) {
+                            if (currentClass == null || currentClass.getSuperclass() == null) {
+                                return false;
+                            }
+                            return currentClass.getName().startsWith(currentClass.getSuperclass().getName()) &&
+                                    currentClass.getName().contains("$$");
+                        }
+                    };
+                }
+            }, true);
+        }
+    }
+}

Modified: tomee/tomee/trunk/examples/myfaces-codi-demo/src/main/resources/META-INF/persistence.xml
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/examples/myfaces-codi-demo/src/main/resources/META-INF/persistence.xml?rev=1599329&r1=1599328&r2=1599329&view=diff
==============================================================================
--- tomee/tomee/trunk/examples/myfaces-codi-demo/src/main/resources/META-INF/persistence.xml (original)
+++ tomee/tomee/trunk/examples/myfaces-codi-demo/src/main/resources/META-INF/persistence.xml Mon Jun  2 19:46:55 2014
@@ -24,9 +24,10 @@ http://java.sun.com/xml/ns/persistence/p
              version="2.0">
 
   <persistence-unit name="demoApplicationPU" transaction-type="RESOURCE_LOCAL">
+    <!-- needed by tomee 1.6.0+-->
+    <non-jta-data-source>demoDS</non-jta-data-source>
 
     <!-- config of (non-)jta-data-source isn't needed if there is just one -->
-
     <!-- @MappedSuperclass classes - see OPENJPA-1926 -->
     <class>org.superbiz.myfaces.domain.AbstractDomainObject</class>
 

Modified: tomee/tomee/trunk/examples/myfaces-codi-demo/src/main/webapp/WEB-INF/faces-config.xml
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/examples/myfaces-codi-demo/src/main/webapp/WEB-INF/faces-config.xml?rev=1599329&r1=1599328&r2=1599329&view=diff
==============================================================================
--- tomee/tomee/trunk/examples/myfaces-codi-demo/src/main/webapp/WEB-INF/faces-config.xml (original)
+++ tomee/tomee/trunk/examples/myfaces-codi-demo/src/main/webapp/WEB-INF/faces-config.xml Mon Jun  2 19:46:55 2014
@@ -22,7 +22,11 @@
               xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
               version="2.0">
 
-  <application>
+    <factory>
+      <lifecycle-factory>org.superbiz.myfaces.startup.ExtValLifecycleFactory</lifecycle-factory>
+    </factory>
+
+    <application>
     <locale-config>
       <default-locale>en</default-locale>
       <supported-locale>en</supported-locale>