You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2016/11/03 11:28:26 UTC

svn commit: r1767871 [3/3] - in /myfaces/tobago/trunk: tobago-core/src/main/java/org/apache/myfaces/tobago/component/ tobago-core/src/main/java/org/apache/myfaces/tobago/facelets/ tobago-core/src/main/java/org/apache/myfaces/tobago/internal/behavior/ t...

Modified: myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/util/HtmlRendererUtils.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/util/HtmlRendererUtils.java?rev=1767871&r1=1767870&r2=1767871&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/util/HtmlRendererUtils.java (original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/util/HtmlRendererUtils.java Thu Nov  3 11:28:25 2016
@@ -20,12 +20,9 @@
 package org.apache.myfaces.tobago.renderkit.html.util;
 
 import org.apache.myfaces.tobago.component.Attributes;
-import org.apache.myfaces.tobago.component.Facets;
-import org.apache.myfaces.tobago.component.UIForm;
 import org.apache.myfaces.tobago.component.Visual;
 import org.apache.myfaces.tobago.context.Markup;
 import org.apache.myfaces.tobago.context.ResourceManagerUtils;
-import org.apache.myfaces.tobago.internal.component.AbstractUICommand;
 import org.apache.myfaces.tobago.internal.util.FacesContextUtils;
 import org.apache.myfaces.tobago.internal.webapp.TobagoResponseWriterWrapper;
 import org.apache.myfaces.tobago.renderkit.LabelWithAccessKey;
@@ -33,12 +30,9 @@ import org.apache.myfaces.tobago.renderk
 import org.apache.myfaces.tobago.renderkit.css.FontAwesomeIconEncoder;
 import org.apache.myfaces.tobago.renderkit.css.Style;
 import org.apache.myfaces.tobago.renderkit.css.TobagoClass;
-import org.apache.myfaces.tobago.renderkit.html.Command;
-import org.apache.myfaces.tobago.renderkit.html.CommandMap;
 import org.apache.myfaces.tobago.renderkit.html.DataAttributes;
 import org.apache.myfaces.tobago.renderkit.html.HtmlAttributes;
 import org.apache.myfaces.tobago.renderkit.html.HtmlElements;
-import org.apache.myfaces.tobago.renderkit.html.JsonUtils;
 import org.apache.myfaces.tobago.renderkit.util.RenderUtils;
 import org.apache.myfaces.tobago.util.ComponentUtils;
 import org.apache.myfaces.tobago.util.FacetUtils;
@@ -275,46 +269,6 @@ public final class HtmlRendererUtils {
     }
   }
 
-  /**
-   * @deprecated Use client behaviour instead.
-   */
-  @Deprecated
-  public static void renderCommandFacet(
-      final UIComponent component, final FacesContext facesContext, final TobagoResponseWriter writer)
-      throws IOException {
-    renderCommandFacet(component, component.getClientId(facesContext), facesContext, writer);
-  }
-
-  /**
-   * @deprecated Use client behaviour instead.
-   */
-  @Deprecated
-  public static void renderCommandFacet(
-      final UIComponent component, final String id, final FacesContext facesContext, final TobagoResponseWriter writer)
-      throws IOException {
-    if (ComponentUtils.getBooleanAttribute(component, Attributes.readonly)
-        || ComponentUtils.getBooleanAttribute(component, Attributes.disabled)) {
-      return;
-    }
-    CommandMap commandMap = null;
-    final Map<String, UIComponent> facets = component.getFacets();
-    for (final Map.Entry<String, UIComponent> entry : facets.entrySet()) {
-      final UIComponent facetComponent = entry.getValue();
-      final String key = entry.getKey();
-      if (facetComponent.isRendered()
-          && (facetComponent instanceof AbstractUICommand || facetComponent instanceof UIForm)
-          && Facets.isEvent(key)) {
-        if (commandMap == null) {
-          commandMap = new CommandMap();
-        }
-        commandMap.addCommand(key, new Command(facesContext, entry.getValue(), id));
-      }
-    }
-    if (commandMap != null) {
-      writer.writeAttribute(DataAttributes.COMMANDS, JsonUtils.encode(commandMap), true);
-    }
-  }
-
   public static void encodeContextMenu(
       final FacesContext facesContext, final TobagoResponseWriter writer, final UIComponent parent)
       throws IOException {

Modified: myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/util/RenderUtils.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/util/RenderUtils.java?rev=1767871&r1=1767870&r2=1767871&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/util/RenderUtils.java (original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/util/RenderUtils.java Thu Nov  3 11:28:25 2016
@@ -19,21 +19,22 @@
 
 package org.apache.myfaces.tobago.renderkit.util;
 
+import org.apache.myfaces.tobago.component.ClientBehaviors;
 import org.apache.myfaces.tobago.internal.component.AbstractUICommand;
+import org.apache.myfaces.tobago.internal.component.AbstractUICommandBase;
 import org.apache.myfaces.tobago.internal.component.AbstractUIData;
 import org.apache.myfaces.tobago.internal.util.StringUtils;
 import org.apache.myfaces.tobago.model.ExpandedState;
 import org.apache.myfaces.tobago.model.SelectedState;
 import org.apache.myfaces.tobago.model.TreePath;
 import org.apache.myfaces.tobago.renderkit.html.AjaxClientBehaviorRenderer;
+import org.apache.myfaces.tobago.renderkit.html.Command;
 import org.apache.myfaces.tobago.renderkit.html.CommandMap;
 import org.apache.myfaces.tobago.renderkit.html.JsonUtils;
 import org.apache.myfaces.tobago.util.ComponentUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import javax.faces.application.Application;
-import javax.faces.application.ViewHandler;
 import javax.faces.component.EditableValueHolder;
 import javax.faces.component.UIComponent;
 import javax.faces.component.UIParameter;
@@ -204,10 +205,8 @@ public final class RenderUtils {
     return null;
   }
 
-  public static String generateUrl(final FacesContext facesContext, final AbstractUICommand component) {
+  public static String generateUrl(final FacesContext facesContext, final AbstractUICommandBase component) {
 
-    final Application application = facesContext.getApplication();
-    final ViewHandler viewHandler = application.getViewHandler();
     final ExternalContext externalContext = facesContext.getExternalContext();
 
     String url = null;
@@ -257,6 +256,13 @@ public final class RenderUtils {
 
     final CommandMap map = new CommandMap();
     addBehaviorCommands(facesContext, holder, map);
+
+    // if there is no explicit behavior (with f:ajax or tc:event), use the command properties as default.
+    // tbd: think about refactoring: put this into ClientBehaviorRenderer
+    if (map.isEmpty() && holder instanceof AbstractUICommand) {
+      map.addCommand(ClientBehaviors.click, new Command(facesContext, (AbstractUICommand) holder));
+    }
+
     if (map.isEmpty()) {
       return null;
     } else {

Modified: myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-sheet.js
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-sheet.js?rev=1767871&r1=1767870&r2=1767871&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-sheet.js (original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-sheet.js Thu Nov  3 11:28:25 2016
@@ -56,9 +56,9 @@ Tobago.Sheet.init = function(elements) {
     var dblclick = commands ? commands.dblclick : undefined;
     new Tobago.Sheet(id, undefined, undefined, undefined, undefined,
         click != undefined ? click.action  : undefined,
-        click != undefined ? click.partially : undefined,
+        click != undefined ? click.partially : undefined, // fixme: partially no longer used
         dblclick != undefined ? dblclick.action : undefined,
-        dblclick != undefined ? dblclick.partially: undefined,
+        dblclick != undefined ? dblclick.partially: undefined, // fixme: partially no longer used
         sheet.data("tobago-behavior-commands")); // type array
 
     //////////////////////////////////////////////

Modified: myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago.js
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago.js?rev=1767871&r1=1767870&r2=1767871&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago.js (original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago.js Thu Nov  3 11:28:25 2016
@@ -453,17 +453,19 @@ var Tobago = {
       });
     }
     if (commands.complete) {
-      if (commands.complete.execute || commands.complete.render) {
-        jsf.ajax.request(
-            jQuery(this).attr("id"),
-            null,
-            {
-              "javax.faces.behavior.event": "complete",
-              execute: commands.complete.execute,
-              render: commands.complete.render
-            });
-      } else {
-        Tobago.submitAction(this, commands.complete.action, commands.complete);
+      if (command.val() >= parseFloat(command.attr("max"))) {
+        if (commands.complete.execute || commands.complete.render) {
+          jsf.ajax.request(
+              jQuery(this).attr("id"),
+              null,
+              {
+                "javax.faces.behavior.event": "complete",
+                execute: commands.complete.execute,
+                render: commands.complete.render
+              });
+        } else {
+          Tobago.submitAction(this, commands.complete.action, commands.complete);
+        }
       }
     }
     if (commands.load) {

Modified: myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/test/java/org/apache/myfaces/tobago/renderkit/html/JsonUtilsUnitTest.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/test/java/org/apache/myfaces/tobago/renderkit/html/JsonUtilsUnitTest.java?rev=1767871&r1=1767870&r2=1767871&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/test/java/org/apache/myfaces/tobago/renderkit/html/JsonUtilsUnitTest.java (original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/test/java/org/apache/myfaces/tobago/renderkit/html/JsonUtilsUnitTest.java Thu Nov  3 11:28:25 2016
@@ -20,6 +20,7 @@
 package org.apache.myfaces.tobago.renderkit.html;
 
 import org.apache.myfaces.tobago.component.Attributes;
+import org.apache.myfaces.tobago.component.ClientBehaviors;
 import org.apache.myfaces.tobago.component.RendererTypes;
 import org.apache.myfaces.tobago.component.UIButton;
 import org.apache.myfaces.tobago.internal.component.AbstractUICommand;
@@ -55,7 +56,7 @@ public class JsonUtilsUnitTest extends A
   @Test
   public void change() {
     final CommandMap map = new CommandMap();
-    map.addCommand("change", new Command(null, null, null, null, null, null, null, null, null, null));
+    map.addCommand(ClientBehaviors.change, new Command(null, null, null, null, null, null, null, null, null, null));
     final String expected = "{'change':{}}".replaceAll("'", "\"");
     Assert.assertEquals(expected, JsonUtils.encode(map));
   }
@@ -63,8 +64,8 @@ public class JsonUtilsUnitTest extends A
   @Test
   public void two() {
     final CommandMap map = new CommandMap();
-    map.addCommand("click", new Command(null, null, "target", null, null, null, null, null, null, null));
-    map.addCommand("change", new Command(null, null, null, null, null, null, null, null, null, null));
+    map.addCommand(ClientBehaviors.click, new Command(null, null, "target", null, null, null, null, null, null, null));
+    map.addCommand(ClientBehaviors.change, new Command(null, null, null, null, null, null, null, null, null, null));
     final String expected = "{'click':{'target':'target'},'change':{}}".replaceAll("'", "\"");
     Assert.assertEquals(expected, JsonUtils.encode(map));
   }

Modified: myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/processor/FacesConfigGenerator.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/processor/FacesConfigGenerator.java?rev=1767871&r1=1767870&r2=1767871&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/processor/FacesConfigGenerator.java (original)
+++ myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/processor/FacesConfigGenerator.java Thu Nov  3 11:28:25 2016
@@ -120,6 +120,9 @@ public class FacesConfigGenerator extend
   private static final String RENDER_KIT_CLASS = "render-kit-class";
   private static final String RENDERER_TYPE = "renderer-type";
   private static final String RENDERER_CLASS = "renderer-class";
+  private static final String BEHAVIOR = "behavior";
+  private static final String BEHAVIOR_ID = "behavior-id";
+  private static final String BEHAVIOR_CLASS = "behavior-class";
   private static final String CLIENT_BEHAVIOR_RENDERER = "client-behavior-renderer";
   private static final String CLIENT_BEHAVIOR_RENDERER_TYPE = "client-behavior-renderer-type";
   private static final String CLIENT_BEHAVIOR_RENDERER_CLASS = "client-behavior-renderer-class";
@@ -206,6 +209,15 @@ public class FacesConfigGenerator extend
         renderKit.addContent(renderKitClass);
         renderKit.addContent(newRenderer);
 
+        final org.jdom.Element behavior = new org.jdom.Element(BEHAVIOR, namespace);
+        final org.jdom.Element behaviorId = new org.jdom.Element(BEHAVIOR_ID, namespace);
+        behaviorId.setText("org.apache.myfaces.tobago.behavior.Event");
+        behavior.addContent(behaviorId);
+        final org.jdom.Element behaviorClass = new org.jdom.Element(BEHAVIOR_CLASS, namespace);
+        behaviorClass.setText("org.apache.myfaces.tobago.behavior.EventBehavior");
+        behavior.addContent(behaviorClass);
+        renderKit.addContent(behavior);
+
         final org.jdom.Element clientBehaviorRender = new org.jdom.Element(CLIENT_BEHAVIOR_RENDERER, namespace);
         final org.jdom.Element clientBehaviorType = new org.jdom.Element(CLIENT_BEHAVIOR_RENDERER_TYPE, namespace);
         clientBehaviorType.setText("javax.faces.behavior.Ajax");
@@ -215,6 +227,15 @@ public class FacesConfigGenerator extend
         clientBehaviorRender.addContent(clientBehaviorClass);
         renderKit.addContent(clientBehaviorRender);
 
+        final org.jdom.Element clientBehaviorRender2 = new org.jdom.Element(CLIENT_BEHAVIOR_RENDERER, namespace);
+        final org.jdom.Element clientBehaviorType2 = new org.jdom.Element(CLIENT_BEHAVIOR_RENDERER_TYPE, namespace);
+        clientBehaviorType2.setText("org.apache.myfaces.tobago.behavior.Event");
+        clientBehaviorRender2.addContent(clientBehaviorType2);
+        final org.jdom.Element clientBehaviorClass2 = new org.jdom.Element(CLIENT_BEHAVIOR_RENDERER_CLASS, namespace);
+        clientBehaviorClass2.setText("org.apache.myfaces.tobago.renderkit.html.AjaxClientBehaviorRenderer");
+        clientBehaviorRender2.addContent(clientBehaviorClass2);
+        renderKit.addContent(clientBehaviorRender2);
+
         final int lastIndex = getIndexAfter(rootElement, CONVERTER, COMPONENT, FACTORY, APPLICATION);
         rootElement.addContent(lastIndex, renderKit);
       }

Modified: myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/resources/org/apache/myfaces/tobago/apt/component.stg
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/resources/org/apache/myfaces/tobago/apt/component.stg?rev=1767871&r1=1767870&r2=1767871&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/resources/org/apache/myfaces/tobago/apt/component.stg (original)
+++ myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/resources/org/apache/myfaces/tobago/apt/component.stg Thu Nov  3 11:28:25 2016
@@ -382,6 +382,10 @@ LabelLayoutProperty(property) ::= <<
 <NormalProperty(property)>
 >>
 
+ClientBehaviorsProperty(property) ::= <<
+<NormalProperty(property)>
+>>
+
 DoubleProperty(property) ::= <<
 <NormalProperty(property)>
 >>