[richfaces-svn-commits] JBoss Rich Faces SVN: r18956 - in trunk: examples/core-demo and 3 other directories.

richfaces-svn-commits at lists.jboss.org richfaces-svn-commits at lists.jboss.org
Tue Aug 24 13:58:49 EDT 2010


Author: nbelaevski
Date: 2010-08-24 13:58:48 -0400 (Tue, 24 Aug 2010)
New Revision: 18956

Modified:
   trunk/core/impl/src/main/java/org/ajax4jsf/renderkit/AjaxRendererUtils.java
   trunk/examples/core-demo/
   trunk/ui/core/ui/src/main/java/org/richfaces/component/AbstractAttachQueue.java
   trunk/ui/core/ui/src/main/java/org/richfaces/view/facelets/html/AjaxHandler.java
   trunk/ui/core/ui/src/main/java/org/richfaces/view/facelets/html/BehaviorStack.java
   trunk/ui/core/ui/src/main/java/org/richfaces/view/facelets/html/BehaviorsAddingComponentHandlerWrapper.java
   trunk/ui/core/ui/src/main/java/org/richfaces/view/facelets/html/BehaviorsTagHandlerDelegateFactoryImpl.java
   trunk/ui/core/ui/src/test/java/org/richfaces/view/facelets/html/AttachQueueHandlerTest.java
Log:
https://jira.jboss.org/browse/RF-9130
https://jira.jboss.org/browse/RF-9025

Modified: trunk/core/impl/src/main/java/org/ajax4jsf/renderkit/AjaxRendererUtils.java
===================================================================
--- trunk/core/impl/src/main/java/org/ajax4jsf/renderkit/AjaxRendererUtils.java	2010-08-24 17:49:57 UTC (rev 18955)
+++ trunk/core/impl/src/main/java/org/ajax4jsf/renderkit/AjaxRendererUtils.java	2010-08-24 17:58:48 UTC (rev 18956)
@@ -133,6 +133,8 @@
     public static final String AJAX_COMPONENT_ID_PARAMETER = "org.richfaces.ajax.component";
     public static final String BEHAVIOR_EVENT_PARAMETER = "javax.faces.behavior.event";
 
+    public static final String QUEUE_ID_ATTRIBUTE = "queueId";
+
     private static final String BEFOREDOMUPDATE_ELEMENT_NAME = "beforedomupdate";
     private static final String COMPLETE_ELEMENT_NAME = "complete";
     private static final String DATA_ELEMENT_NAME = "data";
@@ -324,6 +326,8 @@
         if (isNotEmpty(handlerScript)) {
             ajaxEventOptions.set(behaviorName, handlerScript);
         }
+
+        ajaxEventOptions.set(QUEUE_ID_ATTRIBUTE, getQueueId(component));
         
         ajaxEventOptions.set("incId", "1");
     }
@@ -723,6 +727,10 @@
 //      return statusId;
     }
 
+    public static String getQueueId(UIComponent component) {
+        return (String) component.getAttributes().get(QUEUE_ID_ATTRIBUTE);
+    }
+    
     public static JSFunctionDefinition buildAjaxOncomplete(String body) {
         JSFunctionDefinition function = new JSFunctionDefinition("request", "event", "data");
 


Property changes on: trunk/examples/core-demo
___________________________________________________________________
Name: svn:ignore
   - target
.settings
.project
.classpath
.clover
.externalToolBuilders


   + target
.settings
.project
.classpath
.clover
.externalToolBuilders
bin


Modified: trunk/ui/core/ui/src/main/java/org/richfaces/component/AbstractAttachQueue.java
===================================================================
--- trunk/ui/core/ui/src/main/java/org/richfaces/component/AbstractAttachQueue.java	2010-08-24 17:49:57 UTC (rev 18955)
+++ trunk/ui/core/ui/src/main/java/org/richfaces/component/AbstractAttachQueue.java	2010-08-24 17:58:48 UTC (rev 18956)
@@ -33,6 +33,7 @@
 import javax.faces.event.PostAddToViewEvent;
 
 import org.ajax4jsf.component.behavior.AjaxBehavior;
+import org.ajax4jsf.renderkit.AjaxRendererUtils;
 import org.richfaces.cdk.annotations.Attribute;
 import org.richfaces.cdk.annotations.JsfComponent;
 import org.richfaces.cdk.annotations.JsfRenderer;
@@ -56,8 +57,6 @@
     
     public static final String COMPONENT_FAMILY = "org.richfaces.AttachQueue";
     
-    public static final String QUEUE_ID_ATTRIBUTE = "queueId";
-
     private transient List<UIComponent> componentsToAssociate;
     
     private transient List<AjaxBehavior> behaviorsToAssociate;
@@ -93,7 +92,7 @@
     }
 
     private static void immediateAssociateWith(UIComponent component, String queueId) {
-        component.getAttributes().put(QUEUE_ID_ATTRIBUTE, queueId);
+        component.getAttributes().put(AjaxRendererUtils.QUEUE_ID_ATTRIBUTE, queueId);
     }
 
     private static void immediateAssociateWith(AjaxBehavior behavior, String queueId) {

Modified: trunk/ui/core/ui/src/main/java/org/richfaces/view/facelets/html/AjaxHandler.java
===================================================================
--- trunk/ui/core/ui/src/main/java/org/richfaces/view/facelets/html/AjaxHandler.java	2010-08-24 17:49:57 UTC (rev 18955)
+++ trunk/ui/core/ui/src/main/java/org/richfaces/view/facelets/html/AjaxHandler.java	2010-08-24 17:58:48 UTC (rev 18956)
@@ -38,9 +38,12 @@
 import javax.faces.view.BehaviorHolderAttachedObjectTarget;
 import javax.faces.view.facelets.BehaviorConfig;
 import javax.faces.view.facelets.ComponentHandler;
+import javax.faces.view.facelets.CompositeFaceletHandler;
 import javax.faces.view.facelets.FaceletContext;
+import javax.faces.view.facelets.FaceletHandler;
 import javax.faces.view.facelets.MetaRule;
 import javax.faces.view.facelets.TagException;
+import javax.faces.view.facelets.TagHandler;
 
 import org.ajax4jsf.component.behavior.AjaxBehavior;
 import org.richfaces.component.AbstractAttachQueue;
@@ -57,6 +60,31 @@
         super(config);
     }
 
+    public boolean isWrapping() {
+        if (this.nextHandler instanceof TagHandler) {
+            return !(this.nextHandler instanceof AttachQueueHandler);
+        }
+        
+        if (this.nextHandler instanceof CompositeFaceletHandler) {
+            FaceletHandler[] handlers = ((CompositeFaceletHandler) this.nextHandler).getHandlers();
+            for (FaceletHandler handler : handlers) {
+                if (handler instanceof TagHandler) {
+                    if (handler instanceof AttachQueueHandler) {
+                        continue;
+                    }
+                    
+                    return true;
+                }
+                
+                if (handler instanceof CompositeFaceletHandler) {
+                    return true;
+                }
+            }
+        }
+        
+        return false;
+    }
+    
     public void apply(FaceletContext ctx, UIComponent parent) throws IOException {
 
         Application application = ctx.getFacesContext().getApplication();
@@ -81,7 +109,7 @@
 
             BehaviorInfo behaviorInfo = ajaxBehaviors.popBehavior();
             if (behaviorInfo != null) {
-                if (behaviorInfo.isWrapping()) {
+                if (isWrapping()) {
                     AbstractAttachQueue attachQueue = attachQueueInfo.getAttachQueue();
                     if (attachQueue != null) {
                         List<ClientBehavior> behaviors = behaviorInfo.getBehaviors();

Modified: trunk/ui/core/ui/src/main/java/org/richfaces/view/facelets/html/BehaviorStack.java
===================================================================
--- trunk/ui/core/ui/src/main/java/org/richfaces/view/facelets/html/BehaviorStack.java	2010-08-24 17:49:57 UTC (rev 18955)
+++ trunk/ui/core/ui/src/main/java/org/richfaces/view/facelets/html/BehaviorStack.java	2010-08-24 17:58:48 UTC (rev 18956)
@@ -80,13 +80,6 @@
         }
     }
 
-    void markWrapping() {
-        if (!behaviorStack.isEmpty()) {
-            BehaviorInfoImpl behaviorInfo = behaviorStack.getFirst();
-            behaviorInfo.markWrapping();
-        }
-    }
-
     public void pushBehavior(FacesContext context, ClientBehavior clientBehavior, String behaviorId, String eventName) {
 
         Object behaviorState = ((StateHolder) clientBehavior).saveState(context);
@@ -107,7 +100,6 @@
 
         public List<ClientBehavior> getBehaviors();
 
-        public boolean isWrapping();
     }
 
     private static class BehaviorInfoImpl implements BehaviorInfo {
@@ -116,7 +108,6 @@
         private Object behaviorState;
         private String eventName;
         private List<ClientBehavior> behaviors;
-        private boolean wrapping = false;
 
         public BehaviorInfoImpl(String behaviorId, String eventName, Object behaviorState) {
             this.behaviorId = behaviorId;
@@ -146,14 +137,6 @@
             return behaviors;
         }
 
-        public boolean isWrapping() {
-            return wrapping;
-        }
-
-        private void markWrapping() {
-            wrapping = true;
-        }
-
         private boolean shouldAddBehavior(ClientBehaviorHolder behaviorHolder, String eventName) {
             if (!behaviorHolder.getEventNames().contains(eventName)) {
                 return false;

Modified: trunk/ui/core/ui/src/main/java/org/richfaces/view/facelets/html/BehaviorsAddingComponentHandlerWrapper.java
===================================================================
--- trunk/ui/core/ui/src/main/java/org/richfaces/view/facelets/html/BehaviorsAddingComponentHandlerWrapper.java	2010-08-24 17:49:57 UTC (rev 18955)
+++ trunk/ui/core/ui/src/main/java/org/richfaces/view/facelets/html/BehaviorsAddingComponentHandlerWrapper.java	2010-08-24 17:58:48 UTC (rev 18956)
@@ -36,8 +36,6 @@
 import javax.faces.view.facelets.Tag;
 import javax.faces.view.facelets.TagAttribute;
 
-import org.richfaces.component.AbstractAttachQueue;
-
 /**
  * @author Nick Belaevski
  */
@@ -102,10 +100,6 @@
         BehaviorStack behaviorStack = BehaviorStack.getBehaviorStack(facesContext, false);
 
         if (behaviorStack != null && !behaviorStack.isEmpty()) {
-            if (!(c instanceof AbstractAttachQueue)) {
-                behaviorStack.markWrapping();
-            }
-
             if (c instanceof ClientBehaviorHolder) {
                 ClientBehaviorHolder behaviorHolder = (ClientBehaviorHolder) c;
 

Modified: trunk/ui/core/ui/src/main/java/org/richfaces/view/facelets/html/BehaviorsTagHandlerDelegateFactoryImpl.java
===================================================================
--- trunk/ui/core/ui/src/main/java/org/richfaces/view/facelets/html/BehaviorsTagHandlerDelegateFactoryImpl.java	2010-08-24 17:49:57 UTC (rev 18955)
+++ trunk/ui/core/ui/src/main/java/org/richfaces/view/facelets/html/BehaviorsTagHandlerDelegateFactoryImpl.java	2010-08-24 17:58:48 UTC (rev 18956)
@@ -23,6 +23,9 @@
 
 package org.richfaces.view.facelets.html;
 
+import java.util.Locale;
+
+import javax.faces.application.Application;
 import javax.faces.view.facelets.BehaviorHandler;
 import javax.faces.view.facelets.ComponentHandler;
 import javax.faces.view.facelets.ConverterHandler;
@@ -30,16 +33,40 @@
 import javax.faces.view.facelets.TagHandlerDelegateFactory;
 import javax.faces.view.facelets.ValidatorHandler;
 
+import org.richfaces.log.RichfacesLogger;
+import org.slf4j.Logger;
+
 /**
  * @author Nick Belaevski
  */
 public class BehaviorsTagHandlerDelegateFactoryImpl extends TagHandlerDelegateFactory {
+
+    private static final Logger LOGGER = RichfacesLogger.WEBAPP.getLogger();
+    
     private TagHandlerDelegateFactory factory;
 
+    private boolean isMyFaces = false;
+    
     public BehaviorsTagHandlerDelegateFactoryImpl(TagHandlerDelegateFactory factory) {
         this.factory = factory;
+        detectMyFaces();
     }
 
+    private void detectMyFaces() {
+        String implementationTitle = Application.class.getPackage().getImplementationTitle();
+        if (implementationTitle != null) {
+            isMyFaces = implementationTitle.toLowerCase(Locale.US).contains("myfaces");
+            
+            if (isMyFaces) {
+                //TODO - RF M3 workaround for https://jira.jboss.org/browse/RF-9025 / https://issues.apache.org/jira/browse/MYFACES-2888
+                LOGGER.warn("MyFaces implementation of JavaServer Faces detected. " +
+                		"Wrapping of components using RichFaces behaviors (a4j:ajax etc.) won't work!");
+            }
+        } else {
+            LOGGER.warn("Cannot detect Mojarra vs MyFaces implementation of JavaServer Faces");
+        }
+    }
+    
     /*
      *  (non-Javadoc)
      * @see javax.faces.view.facelets.TagHandlerDelegateFactory#createBehaviorHandlerDelegate(javax.faces.view.facelets.BehaviorHandler)
@@ -59,18 +86,13 @@
         // TagHandlers structure is created when view is compiled
         // so there's no need to check for BehaviorsStack
         
-        ComponentHandler wrappedHandler = owner;
+        ComponentHandler handler = owner;
 
-        //TODO - consider re-wrapping by smb. other, use attributes to handle
-        if (wrappedHandler instanceof BehaviorsAddingComponentHandlerWrapper) {
-            //MyFaces calls delegate factory just in ComponentHandler class ctor, so this is to avoid infinite recursion
-            //our delegate is fine with null value
-            return null;
-        } else {
-            wrappedHandler = new BehaviorsAddingComponentHandlerWrapper(owner);
+        if (!isMyFaces) {
+            handler = new BehaviorsAddingComponentHandlerWrapper(owner);
         }
         
-        return factory.createComponentHandlerDelegate(wrappedHandler);
+        return factory.createComponentHandlerDelegate(handler);
     }
 
     /*

Modified: trunk/ui/core/ui/src/test/java/org/richfaces/view/facelets/html/AttachQueueHandlerTest.java
===================================================================
--- trunk/ui/core/ui/src/test/java/org/richfaces/view/facelets/html/AttachQueueHandlerTest.java	2010-08-24 17:49:57 UTC (rev 18955)
+++ trunk/ui/core/ui/src/test/java/org/richfaces/view/facelets/html/AttachQueueHandlerTest.java	2010-08-24 17:58:48 UTC (rev 18956)
@@ -38,6 +38,7 @@
 import javax.faces.view.ViewDeclarationLanguage;
 
 import org.ajax4jsf.component.behavior.AjaxBehavior;
+import org.ajax4jsf.renderkit.AjaxRendererUtils;
 import org.jboss.test.faces.FacesEnvironment;
 import org.jboss.test.faces.FacesEnvironment.FacesRequest;
 import org.junit.After;
@@ -122,7 +123,7 @@
         UIComponent attachQueue = viewRoot.findComponent(attachQueueId);
         
         assertTrue(attachQueue instanceof AbstractAttachQueue);
-        assertNull(attachQueue.getParent().getAttributes().get(AbstractAttachQueue.QUEUE_ID_ATTRIBUTE));
+        assertNull(attachQueue.getParent().getAttributes().get(AjaxRendererUtils.QUEUE_ID_ATTRIBUTE));
     }
     
     @Test
@@ -146,7 +147,7 @@
         buildView("/attachQueueWithParentComponent.xhtml");
         
         UIComponent link = viewRoot.findComponent(":form:link");
-        assertEquals("form:attachQueue", link.getAttributes().get(AbstractAttachQueue.QUEUE_ID_ATTRIBUTE));
+        assertEquals("form:attachQueue", link.getAttributes().get(AjaxRendererUtils.QUEUE_ID_ATTRIBUTE));
     }
     
     @Test



More information about the richfaces-svn-commits mailing list