myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cjhow...@apache.org
Subject svn commit: r889289 - in /myfaces/shared/trunk_4.0.x/core/src/main/java/org/apache/myfaces/shared/renderkit/html: HtmlButtonRendererBase.java HtmlRendererUtils.java
Date Thu, 10 Dec 2009 15:19:20 GMT
Author: cjhoward
Date: Thu Dec 10 15:19:19 2009
New Revision: 889289

URL: http://svn.apache.org/viewvc?rev=889289&view=rev
Log:
MYFACES-2458 - Make sure AJAX call isn't emitted when <f:ajax disabled="true" />.

Modified:
    myfaces/shared/trunk_4.0.x/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlButtonRendererBase.java
    myfaces/shared/trunk_4.0.x/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlRendererUtils.java

Modified: myfaces/shared/trunk_4.0.x/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlButtonRendererBase.java
URL: http://svn.apache.org/viewvc/myfaces/shared/trunk_4.0.x/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlButtonRendererBase.java?rev=889289&r1=889288&r2=889289&view=diff
==============================================================================
--- myfaces/shared/trunk_4.0.x/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlButtonRendererBase.java
(original)
+++ myfaces/shared/trunk_4.0.x/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlButtonRendererBase.java
Thu Dec 10 15:19:19 2009
@@ -265,11 +265,16 @@
 
         //according to the specification in jsf.util.chain jdocs and the spec document we
have to use
         //jsf.util.chain to chain the functions and
-        return HtmlRendererUtils.buildBehaviorChain(facesContext, uiComponent, behaviors,
+        String behaviorChain = HtmlRendererUtils.buildBehaviorChain(facesContext, uiComponent,
behaviors,
                 ClientBehaviorEvents.CLICK, ClientBehaviorEvents.ACTION, 
                 userOnClick.toString() , rendererOnClick.toString(),
-                HtmlRendererUtils.mapAttachedParamsToStringValues(facesContext, uiComponent))
+ "return false;";
-
+                HtmlRendererUtils.mapAttachedParamsToStringValues(facesContext, uiComponent));
+        
+        if ((behaviorChain != null) && !behaviorChain.equals ("")) {
+            behaviorChain += "return false;";
+        }
+        
+        return behaviorChain;
     }
 
     protected StringBuffer buildOnClick(UIComponent uiComponent, FacesContext facesContext,


Modified: myfaces/shared/trunk_4.0.x/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlRendererUtils.java
URL: http://svn.apache.org/viewvc/myfaces/shared/trunk_4.0.x/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlRendererUtils.java?rev=889289&r1=889288&r2=889289&view=diff
==============================================================================
--- myfaces/shared/trunk_4.0.x/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlRendererUtils.java
(original)
+++ myfaces/shared/trunk_4.0.x/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlRendererUtils.java
Thu Dec 10 15:19:19 2009
@@ -2093,14 +2093,18 @@
                 .iterator();
         while (clientIterator.hasNext())
         {
-
-            //either strings or functions, but I assume string is more appropriate since
it allows access to the
-            //origin as this!
-            target.append("'"
-                    + StringUtils.replace(clientIterator.next().getScript(context), '\'',
"\\'") + "'");
-            if (clientIterator.hasNext())
-            {
-                target.append(", ");
+            String script = clientIterator.next().getScript (context);
+            
+            // The script _can_ be null, and in fact is for <f:ajax disabled="true" />
+            
+            if (script != null) {
+                //either strings or functions, but I assume string is more appropriate since
it allows access to the
+                //origin as this!
+                target.append("'" + StringUtils.replace(script, '\'', "\\'") + "'");
+                if (clientIterator.hasNext())
+                {
+                    target.append(", ");
+                }
             }
         }
 
@@ -2155,19 +2159,25 @@
             finalParams.add('\''+serverEventCode+'\'');
         }
         Iterator<String> it = finalParams.iterator();
-
-        //according to the spec jsf.util.chain has to be used to build up the behavior and
scripts
-        retVal.append("jsf.util.chain(document.getElementById('"
-                + uiComponent.getClientId(facesContext) + "'), event,");
-        while (it.hasNext())
-        {
-            retVal.append(it.next());
-            if(it.hasNext())
+        
+        // It's possible that there are no behaviors to render.  For example, if we have
+        // <f:ajax disabled="true" /> as the only behavior.
+        
+        if (it.hasNext()) {
+            //according to the spec jsf.util.chain has to be used to build up the behavior
and scripts
+            retVal.append("jsf.util.chain(document.getElementById('"
+                    + uiComponent.getClientId(facesContext) + "'), event,");
+            while (it.hasNext())
             {
-                retVal.append(", ");
+                retVal.append(it.next());
+                if(it.hasNext())
+                {
+                    retVal.append(", ");
+                }
             }
+            retVal.append(");");
         }
-        retVal.append(");");
+        
         return retVal.toString();
 
     }
@@ -2225,18 +2235,24 @@
         }
         Iterator<String> it = finalParams.iterator();
 
-        //according to the spec jsf.util.chain has to be used to build up the behavior and
scripts
-        retVal.append("jsf.util.chain(document.getElementById('"
-                + uiComponent.getClientId(facesContext) + "'), event,");
-        while (it.hasNext())
-        {
-            retVal.append(it.next());
-            if (it.hasNext())
+        // It's possible that there are no behaviors to render.  For example, if we have
+        // <f:ajax disabled="true" /> as the only behavior.
+        
+        if (it.hasNext()) {
+            //according to the spec jsf.util.chain has to be used to build up the behavior
and scripts
+            retVal.append("jsf.util.chain(document.getElementById('"
+                    + uiComponent.getClientId(facesContext) + "'), event,");
+            while (it.hasNext())
             {
-                retVal.append(", ");
+                retVal.append(it.next());
+                if (it.hasNext())
+                {
+                    retVal.append(", ");
+                }
             }
+            retVal.append(");");
         }
-        retVal.append(");");
+        
         return retVal.toString();
 
     }



Mime
View raw message