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 2012/09/04 17:39:00 UTC

svn commit: r1380682 - in /myfaces/tobago/trunk: tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/ tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/ tobago-theme...

Author: lofwyr
Date: Tue Sep  4 15:38:59 2012
New Revision: 1380682

URL: http://svn.apache.org/viewvc?rev=1380682&view=rev
Log:
TOBAGO-1192: buttons and links rendering without javascript fragments
 - getting popups to work

Added:
    myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/JsonUtils.java
    myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/Popup.java
    myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/test/java/org/apache/myfaces/tobago/renderkit/html/JsonUtilsUnitTest.java
Modified:
    myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUICommandBase.java
    myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/ButtonRenderer.java
    myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/LinkRenderer.java
    myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/Command.java
    myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/CommandMap.java
    myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago.js

Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUICommandBase.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUICommandBase.java?rev=1380682&r1=1380681&r2=1380682&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUICommandBase.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUICommandBase.java Tue Sep  4 15:38:59 2012
@@ -19,7 +19,11 @@
 
 package org.apache.myfaces.tobago.internal.component;
 
+import org.apache.myfaces.tobago.component.Facets;
+import org.apache.myfaces.tobago.component.OnComponentPopulated;
 import org.apache.myfaces.tobago.component.SupportsRenderedPartially;
+import org.apache.myfaces.tobago.event.PopupFacetActionListener;
+import org.apache.myfaces.tobago.util.ComponentUtils;
 
 import javax.faces.component.UIComponent;
 import javax.faces.context.FacesContext;
@@ -28,7 +32,16 @@ import javax.faces.event.PhaseId;
 import java.util.Iterator;
 
 public abstract class AbstractUICommandBase extends javax.faces.component.UICommand
-    implements SupportsRenderedPartially {
+    implements SupportsRenderedPartially, OnComponentPopulated {
+
+  public void onComponentPopulated(FacesContext facesContext, UIComponent parent) {
+    AbstractUIPopup popup = (AbstractUIPopup) getFacet(Facets.POPUP);
+    if (popup != null) {
+      if (!ComponentUtils.containsPopupActionListener(this)) {
+        addActionListener(new PopupFacetActionListener());
+      }
+    }
+  }
 
   public void processDecodes(FacesContext context) {
     if (context == null) {

Modified: myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/ButtonRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/ButtonRenderer.java?rev=1380682&r1=1380681&r2=1380682&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/ButtonRenderer.java (original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/ButtonRenderer.java Tue Sep  4 15:38:59 2012
@@ -37,6 +37,8 @@ import org.apache.myfaces.tobago.renderk
 import org.apache.myfaces.tobago.renderkit.html.HtmlAttributes;
 import org.apache.myfaces.tobago.renderkit.html.HtmlButtonTypes;
 import org.apache.myfaces.tobago.renderkit.html.HtmlElements;
+import org.apache.myfaces.tobago.renderkit.html.JsonUtils;
+import org.apache.myfaces.tobago.renderkit.html.Popup;
 import org.apache.myfaces.tobago.renderkit.html.util.HtmlRendererUtils;
 import org.apache.myfaces.tobago.renderkit.util.RenderUtils;
 import org.apache.myfaces.tobago.util.ComponentUtils;
@@ -78,13 +80,14 @@ public class ButtonRenderer extends Comm
       final CommandMap map = new CommandMap();
       final String[] partialIds
           = HtmlRendererUtils.getComponentIdsAsList(facesContext, button, button.getRenderedPartially());
+      final Popup popup = Popup.createPopup(button);
       final Command click = new Command(
-          button.isTransition(), button.getTarget(), url, partialIds, null, confirmation, null);
+          button.isTransition(), button.getTarget(), url, partialIds, null, confirmation, null, popup);
       if (button.getOnclick() != null) {
         click.setScript(button.getOnclick());
       }
       map.setClick(click);
-      writer.writeAttribute(DataAttributes.ACTION, map.encodeJson(), true);
+      writer.writeAttribute(DataAttributes.ACTION, JsonUtils.encode(map), true);
 
       writer.writeAttribute(HtmlAttributes.HREF, "#", false);
 

Modified: myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/LinkRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/LinkRenderer.java?rev=1380682&r1=1380681&r2=1380682&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/LinkRenderer.java (original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/LinkRenderer.java Tue Sep  4 15:38:59 2012
@@ -34,6 +34,8 @@ import org.apache.myfaces.tobago.renderk
 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.html.Popup;
 import org.apache.myfaces.tobago.renderkit.html.util.HtmlRendererUtils;
 import org.apache.myfaces.tobago.renderkit.util.RenderUtils;
 import org.apache.myfaces.tobago.webapp.TobagoResponseWriter;
@@ -75,13 +77,14 @@ public class LinkRenderer extends Comman
       final CommandMap map = new CommandMap();
       final String[] partialIds
           = HtmlRendererUtils.getComponentIdsAsList(facesContext, link, link.getRenderedPartially());
+      final Popup popup = Popup.createPopup(link);
       final Command click = new Command(
-          link.isTransition(), link.getTarget(), url, partialIds, null, confirmation, null);
+          link.isTransition(), link.getTarget(), url, partialIds, null, confirmation, null, popup);
       if (link.getOnclick() != null) {
         click.setScript(link.getOnclick());
       }
       map.setClick(click);
-      writer.writeAttribute(DataAttributes.ACTION, map.encodeJson(), true);
+      writer.writeAttribute(DataAttributes.ACTION, JsonUtils.encode(map), true);
 
       writer.writeAttribute(HtmlAttributes.HREF, "#", false);
 

Modified: myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/Command.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/Command.java?rev=1380682&r1=1380681&r2=1380682&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/Command.java (original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/Command.java Tue Sep  4 15:38:59 2012
@@ -32,6 +32,7 @@ public class Command {
   private String focus;
   private String confirmation;
   private Integer delay;
+  private Popup popup;
   /**
    * @deprecated
    */
@@ -40,7 +41,7 @@ public class Command {
 
   public Command(
       Boolean transition, String target, String url, String[] partially, String focus, String confirmation,
-      Integer delay) {
+      Integer delay, Popup popup) {
     this.transition = transition;
     this.target = target;
     this.url = url;
@@ -48,6 +49,78 @@ public class Command {
     this.focus = focus;
     this.confirmation = confirmation;
     this.delay = delay;
+    this.popup = popup;
+  }
+
+  public Boolean getTransition() {
+    return transition;
+  }
+
+  public void setTransition(Boolean transition) {
+    this.transition = transition;
+  }
+
+  public String getTarget() {
+    return target;
+  }
+
+  public void setTarget(String target) {
+    this.target = target;
+  }
+
+  public String getUrl() {
+    return url;
+  }
+
+  public void setUrl(String url) {
+    this.url = url;
+  }
+
+  public String[] getPartially() {
+    return partially;
+  }
+
+  public void setPartially(String[] partially) {
+    this.partially = partially;
+  }
+
+  public String getFocus() {
+    return focus;
+  }
+
+  public void setFocus(String focus) {
+    this.focus = focus;
+  }
+
+  public String getConfirmation() {
+    return confirmation;
+  }
+
+  public void setConfirmation(String confirmation) {
+    this.confirmation = confirmation;
+  }
+
+  public Integer getDelay() {
+    return delay;
+  }
+
+  public void setDelay(Integer delay) {
+    this.delay = delay;
+  }
+
+  public Popup getPopup() {
+    return popup;
+  }
+
+  public void setPopup(Popup popup) {
+    this.popup = popup;
+  }
+
+  /**
+   * @deprecated
+   */
+  public String getScript() {
+    return script;
   }
 
   /**
@@ -58,74 +131,4 @@ public class Command {
     this.script = script;
   }
 
-  public void encodeJson(StringBuilder builder) {
-    builder.append("{");
-    int initialLength = builder.length();
-    if (transition != null && !transition) { // true is the default, so encoding is needed.
-      encodeJsonAttribute(builder, "transition", transition);
-    }
-    if (target != null) {
-      encodeJsonAttribute(builder, "target", target);
-    }
-    if (url != null) {
-      encodeJsonAttribute(builder, "url", url);
-    }
-    if (partially != null && partially.length > 0) {
-      encodeJsonAttribute(builder, "partially", partially);
-    }
-    if (focus != null) {
-      encodeJsonAttribute(builder, "focus", focus);
-    }
-    if (confirmation != null) {
-      encodeJsonAttribute(builder, "confirmation", confirmation);
-    }
-    if (delay != null) {
-      encodeJsonAttribute(builder, "delay", delay);
-    }
-    if (script != null) {
-      encodeJsonAttribute(builder, "script", script);
-    }
-
-    if (builder.length() - initialLength > 0) {
-      builder.deleteCharAt(builder.length() - 1);
-    }
-
-    builder.append("}");
-  }
-
-  private void encodeJsonAttribute(StringBuilder builder, String name, String[] value) {
-    builder.append("\"");
-    builder.append(name);
-    builder.append("\":\"");
-    boolean colon = false;
-    for (String item : value) {
-      if (colon) {
-        builder.append(",");
-      }
-      builder.append(item);
-      colon = true;
-    }
-    builder.append("\",");
-  }
-
-  private void encodeJsonAttribute(StringBuilder builder, String name, Boolean value) {
-    encodeJsonAttributeIntern(builder, name, Boolean.toString(value));
-  }
-
-  private void encodeJsonAttribute(StringBuilder builder, String name, Integer value) {
-    encodeJsonAttributeIntern(builder,  name, Integer.toString(value));
-  }
-
-  private void encodeJsonAttribute(StringBuilder builder, String name, String value) {
-    value = value.replaceAll("\\\"", "\\\\\\\"");
-    encodeJsonAttributeIntern(builder, name, value);
-  }
-
-  private void encodeJsonAttributeIntern(StringBuilder builder, String name, String value) {
-    builder.append("\"");
-    builder.append(name);
-    builder.append("\":\"");
-    builder.append(value);
-    builder.append("\",");
-  }
 }

Modified: myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/CommandMap.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/CommandMap.java?rev=1380682&r1=1380681&r2=1380682&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/CommandMap.java (original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/CommandMap.java Tue Sep  4 15:38:59 2012
@@ -34,20 +34,7 @@ public class CommandMap {
     this.click = click;
   }
 
-  public String encodeJson() {
-    StringBuilder builder = new StringBuilder();
-    builder.append("{");
-
-    if (click != null) {
-      builder.append("\"click\":");
-      click.encodeJson(builder);
-      builder.append(",");
-    }
-
-    if (builder.charAt(builder.length() - 1) == ',') {
-      builder.deleteCharAt(builder.length() - 1);
-    }
-    builder.append("}");
-    return builder.toString();
+  public Command getClick() {
+    return click;
   }
 }

Added: myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/JsonUtils.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/JsonUtils.java?rev=1380682&view=auto
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/JsonUtils.java (added)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/JsonUtils.java Tue Sep  4 15:38:59 2012
@@ -0,0 +1,159 @@
+/*
+ * 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.apache.myfaces.tobago.renderkit.html;
+
+public class JsonUtils {
+
+  private JsonUtils() {
+  }
+
+  private static void encode(StringBuilder builder, String name, String[] value) {
+    builder.append("\"");
+    builder.append(name);
+    builder.append("\":\"");
+    boolean colon = false;
+    for (String item : value) {
+      if (colon) {
+        builder.append(",");
+      }
+      builder.append(item);
+      colon = true;
+    }
+    builder.append("\",");
+  }
+
+  static void encode(StringBuilder builder, String name, Boolean value) {
+    builder.append("\"");
+    builder.append(name);
+    builder.append("\":");
+    builder.append(Boolean.toString(value));
+    builder.append(",");
+  }
+
+  static void encode(StringBuilder builder, String name, Integer value) {
+    builder.append("\"");
+    builder.append(name);
+    builder.append("\":");
+    builder.append(Integer.toString(value));
+    builder.append(",");
+  }
+
+  static void encode(StringBuilder builder, String name, String value) {
+    value = value.replaceAll("\\\"", "\\\\\\\"");
+    builder.append("\"");
+    builder.append(name);
+    builder.append("\":\"");
+    builder.append(value);
+    builder.append("\",");
+  }
+
+  public static String encode(CommandMap commandMap) {
+    StringBuilder builder = new StringBuilder();
+    builder.append("{");
+    int initialLength = builder.length();
+
+    Command click = commandMap.getClick();
+    if (click != null) {
+      encode(builder, "click", click);
+    }
+
+    if (builder.length() - initialLength > 0) {
+      assert builder.charAt(builder.length() - 1) == ',';
+      builder.deleteCharAt(builder.length() - 1);
+    }
+
+    builder.append("}");
+    return builder.toString();
+  }
+
+  static void encode(StringBuilder builder, String name, Command command) {
+    builder.append("\"");
+    builder.append(name);
+    builder.append("\":{");
+    int initialLength = builder.length();
+
+    Boolean transition = command.getTransition();
+    if (transition != null && !transition) { // true is the default, so encoding is needed.
+      encode(builder, "transition", transition);
+    }
+    String target = command.getTarget();
+    if (target != null) {
+      encode(builder, "target", target);
+    }
+    String url = command.getUrl();
+    if (url != null) {
+      encode(builder, "url", url);
+    }
+    String[] partially = command.getPartially();
+    if (partially != null && partially.length > 0) {
+      encode(builder, "partially", partially);
+    }
+    String focus = command.getFocus();
+    if (focus != null) {
+      encode(builder, "focus", focus);
+    }
+    String confirmation = command.getConfirmation();
+    if (confirmation != null) {
+      encode(builder, "confirmation", confirmation);
+    }
+    Integer delay  = command.getDelay();
+    if (delay != null) {
+      encode(builder, "delay", delay);
+    }
+    Popup popup = command.getPopup();
+    if (popup != null) {
+      encode(builder, "popup", popup);
+    }
+    String script = command.getScript();
+    if (script != null) {
+      encode(builder, "script", script);
+    }
+
+    if (builder.length() - initialLength > 0) {
+      assert builder.charAt(builder.length() - 1) == ',';
+      builder.deleteCharAt(builder.length() - 1);
+    }
+
+    builder.append("},");
+  }
+
+  static void encode(StringBuilder builder, String name, Popup popup) {
+    builder.append("\"");
+    builder.append(name);
+    builder.append("\":{");
+    int initialLength = builder.length();
+
+    String command = popup.getCommand();
+    if (command != null) {
+      encode(builder, "command", command);
+    }
+    Boolean immediate = popup.isImmediate();
+    if (immediate != null) {
+      encode(builder, "immediate", immediate);
+    }
+    if (builder.length() - initialLength > 0) {
+      assert builder.charAt(builder.length() - 1) == ',';
+      builder.deleteCharAt(builder.length() - 1);
+    }
+
+    builder.append("},");
+  }
+
+}

Added: myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/Popup.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/Popup.java?rev=1380682&view=auto
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/Popup.java (added)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/Popup.java Tue Sep  4 15:38:59 2012
@@ -0,0 +1,81 @@
+/*
+ * 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.apache.myfaces.tobago.renderkit.html;
+
+import org.apache.myfaces.tobago.component.Attributes;
+import org.apache.myfaces.tobago.internal.component.AbstractUICommand;
+import org.apache.myfaces.tobago.util.ComponentUtils;
+
+public class Popup {
+
+  /**
+   * Can be "open" or "close"
+   */
+  private String command;
+
+  /**
+   * true for close immediately, false for close after submit
+   */
+  private boolean immediate;
+
+  private Popup(String command, boolean immediate) {
+    this.command = command;
+    this.immediate = immediate;
+  }
+
+  public static Popup createPopup(AbstractUICommand component) {
+    String command = null;
+    boolean immediate = false;
+
+    final String popupClose = (String) component.getAttributes().get(Attributes.POPUP_CLOSE);
+    if (popupClose != null) {
+      command = "close";
+      if (popupClose.equals("immediate")) {
+        immediate = true;
+      }
+    } else {
+      boolean popupAction = ComponentUtils.containsPopupActionListener(component);
+      if (popupAction) {
+        command = "open";
+      }
+    }
+    if (command != null) {
+      return new Popup(command, immediate);
+    } else {
+      return null;
+    }
+  }
+
+  public String getCommand() {
+    return command;
+  }
+
+  public void setCommand(String command) {
+    this.command = command;
+  }
+
+  public boolean isImmediate() {
+    return immediate;
+  }
+
+  public void setImmediate(boolean immediate) {
+    this.immediate = immediate;
+  }
+}

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=1380682&r1=1380681&r2=1380682&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 Tue Sep  4 15:38:59 2012
@@ -962,16 +962,31 @@ var Tobago = {
       if (commands.click) {
         command.click(function() {
           if (commands.click.confirmation == null || confirm(commands.click.confirmation)) {
-            var actionId = commands.click.actionId ? commands.click.actionId : jQuery(this).attr("id");
-            if (commands.click.partially) {
-              Tobago.reloadComponent(this, commands.click.partially, actionId, commands.click);
-            } else if (commands.click.url) {
-              Tobago.navigateToUrl(commands.click.url);
-            } else if (commands.click.script) { // XXX this case is deprecated.
-              // not allowed with Content Security Policy (CSP)
-                eval(commands.click.script);
+            var popup = commands.click.popup;
+            if (popup && popup.command == "close" && popup.immediate) {
+              Tobago.Popup.close(this);
             } else {
-              Tobago.submitAction(this, actionId, commands.click);
+              if (popup && popup.command == "close") {
+                Tobago.Popup.unlockBehind();
+              }
+              var actionId = commands.click.actionId ? commands.click.actionId : jQuery(this).attr("id");
+              if (commands.click.partially) {
+                if (popup && popup.command == "open") {
+                  Tobago.Popup.openWithAction(this, commands.click.partially, actionId);
+                } else {
+                  Tobago.reloadComponent(this, commands.click.partially, actionId, commands.click);
+                }
+              } else if (commands.click.url) {
+                Tobago.navigateToUrl(commands.click.url);
+              } else if (commands.click.script) { // XXX this case is deprecated.
+                // not allowed with Content Security Policy (CSP)
+                  eval(commands.click.script);
+              } else {
+                Tobago.submitAction(this, actionId, commands.click);
+              }
+              if (popup && popup.command == "close") {
+                Tobago.Popup.close();
+              }
             }
           }
         });

Added: 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=1380682&view=auto
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/test/java/org/apache/myfaces/tobago/renderkit/html/JsonUtilsUnitTest.java (added)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/test/java/org/apache/myfaces/tobago/renderkit/html/JsonUtilsUnitTest.java Tue Sep  4 15:38:59 2012
@@ -0,0 +1,85 @@
+/*
+ * 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.apache.myfaces.tobago.renderkit.html;
+
+import org.apache.myfaces.tobago.component.Attributes;
+import org.apache.myfaces.tobago.component.ComponentTypes;
+import org.apache.myfaces.tobago.component.RendererTypes;
+import org.apache.myfaces.tobago.component.UICommand;
+import org.apache.myfaces.tobago.internal.mock.faces.AbstractTobagoTestBase;
+import org.apache.myfaces.tobago.util.CreateComponentUtils;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class JsonUtilsUnitTest extends AbstractTobagoTestBase {
+
+  @Test
+  public void empty() {
+    CommandMap commandMap = new CommandMap();
+    Assert.assertEquals("{}", JsonUtils.encode(commandMap));
+  }
+
+  @Test
+  public void click() {
+    CommandMap commandMap = new CommandMap();
+    commandMap.setClick(new Command(null, null, null, new String[0], null, null, null, null));
+    final String expected = "{'click':{}}".replaceAll("'", "\"");
+    Assert.assertEquals(expected, JsonUtils.encode(commandMap));
+  }
+
+  @Test
+  public void transition() {
+    CommandMap commandMap = new CommandMap();
+    commandMap.setClick(new Command(false, null, null, new String[0], null, null, null, null));
+    final String expected = "{'click':{'transition':false}}".replaceAll("'", "\"");
+    Assert.assertEquals(expected, JsonUtils.encode(commandMap));
+  }
+
+  @Test
+  public void more() {
+    CommandMap commandMap = new CommandMap();
+    final UICommand command = (UICommand)
+        CreateComponentUtils.createComponent(facesContext, ComponentTypes.BUTTON, RendererTypes.BUTTON, "command");
+    command.getAttributes().put(Attributes.POPUP_CLOSE, "immediate");
+    command.setRenderedPartially(new String[] {"popup"});
+
+    commandMap.setClick(new Command(
+        false, "_blank", "http://www.apache.org/", new String[]{"id1", "id2"}, "id_focus", "Really?", 1000,
+        Popup.createPopup(command)));
+    final String expected = (
+        "{"
+            + "'click':{"
+            + "'transition':false,"
+            + "'target':'_blank',"
+            + "'url':'http://www.apache.org/',"
+            + "'partially':'id1,id2',"
+            + "'focus':'id_focus',"
+            + "'confirmation':'Really?',"
+            + "'delay':1000,"
+            + "'popup':{"
+            + "'command':'close',"
+            + "'immediate':true"
+            + "}"
+            + "}"
+            + "}").replaceAll("'", "\"");
+    Assert.assertEquals(expected, JsonUtils.encode(commandMap));
+  }
+
+}