myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lof...@apache.org
Subject svn commit: r1466525 - in /myfaces/tobago/trunk: tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/html/ tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/ tobago-theme/tob...
Date Wed, 10 Apr 2013 15:42:23 GMT
Author: lofwyr
Date: Wed Apr 10 15:42:22 2013
New Revision: 1466525

URL: http://svn.apache.org/r1466525
Log:
TOBAGO-1192: buttons and links rendering without javascript fragments
 - also for the menu

Modified:
    myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/html/DataAttributes.java
    myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/MenuCommandRenderer.java
    myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/util/JQueryUtils.java
    myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-menu.js
    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/renderkit/html/DataAttributes.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/html/DataAttributes.java?rev=1466525&r1=1466524&r2=1466525&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/html/DataAttributes.java
(original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/html/DataAttributes.java
Wed Apr 10 15:42:22 2013
@@ -33,6 +33,7 @@ public final class DataAttributes {
   public static final String COLUMNINDEX = "data-tobago-columnindex";
 
   /**
+   * TBD: needed? may replace with VALUE?
    * Custom command attribute. Is used to mark different client side JavaScript buttons.
    * Should only contain the command name as a keyword, for security reasons.
    */

Modified: myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/MenuCommandRenderer.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/MenuCommandRenderer.java?rev=1466525&r1=1466524&r2=1466525&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/MenuCommandRenderer.java
(original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/MenuCommandRenderer.java
Wed Apr 10 15:42:22 2013
@@ -32,13 +32,14 @@ import org.apache.myfaces.tobago.renderk
 import org.apache.myfaces.tobago.renderkit.LabelWithAccessKey;
 import org.apache.myfaces.tobago.renderkit.css.Classes;
 import org.apache.myfaces.tobago.renderkit.css.Style;
+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.HtmlInputTypes;
-import org.apache.myfaces.tobago.renderkit.html.util.CommandRendererHelper;
+import org.apache.myfaces.tobago.renderkit.html.JsonUtils;
 import org.apache.myfaces.tobago.renderkit.html.util.HtmlRendererUtils;
-import org.apache.myfaces.tobago.renderkit.util.JQueryUtils;
 import org.apache.myfaces.tobago.renderkit.util.RenderUtils;
 import org.apache.myfaces.tobago.util.ComponentUtils;
 import org.apache.myfaces.tobago.webapp.TobagoResponseWriter;
@@ -76,17 +77,12 @@ public class MenuCommandRenderer extends
       boolean checked = ComponentUtils.getBooleanAttribute(checkbox, Attributes.VALUE);
       String image = checked ? "image/MenuCheckmark.gif" : null;
       String hiddenId = checkbox.getClientId(facesContext);
-      // the function toggles true <-> false
-      String clientId = menu.getClientId(facesContext);
-      String submit = HtmlRendererUtils.createSubmitAction(clientId, true, null, null);
-      String setValue = JQueryUtils.selectId(hiddenId) 
-          + ".each(function(){jQuery(this).val(jQuery(this).val() == 'true' ? 'false' : 'true')});
";
-      encodeItem(facesContext, writer, menu, label, setValue + submit, disabled, firstLevel,
image);
+      final CommandMap map = new CommandMap(new Command());
+      encodeItem(facesContext, writer, menu, label, map, disabled, firstLevel, image, null,
"selectBoolean");
       encodeHidden(writer, hiddenId, checked);
     } else if (menu.getFacet(Facets.RADIO) != null) {
       // radio menu
       String clientId = menu.getClientId(facesContext);
-      String submit = HtmlRendererUtils.createSubmitAction(clientId, true, null, null);
       UISelectOne radio = (UISelectOne) menu.getFacet(Facets.RADIO);
       List<SelectItem> items = RenderUtils.getSelectItems(radio);
       String hiddenId = radio.getClientId(facesContext);
@@ -105,28 +101,22 @@ public class MenuCommandRenderer extends
         } else {
           LOG.warn("Menu item has label=null where clientId=" + clientId);
         }
-        String formattedValue = RenderUtils.getFormattedValue(facesContext, radio, item.getValue());
-        String setValue = JQueryUtils.selectId(hiddenId) + ".val('" + JQueryUtils.escapeValue(formattedValue)
+ "'); ";
-        encodeItem(facesContext, writer, null, label, setValue + submit, disabled, firstLevel,
image);
+        final String formattedValue = RenderUtils.getFormattedValue(facesContext, radio,
item.getValue());
+        final CommandMap map = new CommandMap(new Command(clientId, null, null, null, null,
null, null, null, null));
+        encodeItem(facesContext, writer, null, label, map, disabled, firstLevel, image, formattedValue,
"selectOne");
       }
       encodeHidden(writer, hiddenId, getCurrentValue(facesContext, radio));
     } else {
       // normal menu command
-      CommandRendererHelper helper = new CommandRendererHelper(facesContext, menu);
-      String onclick = helper.getOnclick();
-      if (onclick == null) {
-        String clientId = menu.getClientId(facesContext);
-        onclick = HtmlRendererUtils.createSubmitAction(clientId, true, null, null);
-      }
       String image = menu.getImage();
-      encodeItem(facesContext, writer, menu, label, onclick, disabled, firstLevel, image);
+      CommandMap map = new CommandMap(new Command(facesContext, menu));
+      encodeItem(facesContext, writer, menu, label, map, disabled, firstLevel, image, null,
null);
     }
   }
 
   private void encodeHidden(TobagoResponseWriter writer, String hiddenId, Object value) throws
IOException {
     writer.startElement(HtmlElements.INPUT, null);
     writer.writeAttribute(HtmlAttributes.TYPE, HtmlInputTypes.HIDDEN, false);
-    writer.writeIdAttribute(hiddenId);
     writer.writeNameAttribute(hiddenId);
     if (value != null) {
       writer.writeAttribute(HtmlAttributes.VALUE, value.toString(), true);
@@ -136,7 +126,8 @@ public class MenuCommandRenderer extends
 
   private void encodeItem(
       FacesContext facesContext, TobagoResponseWriter writer, UIMenuCommand component, LabelWithAccessKey
label,
-      String onclick, boolean disabled, boolean firstLevel, String image) throws IOException
{
+      CommandMap map, boolean disabled, boolean firstLevel, String image, String value, String
sub)
+      throws IOException {
 
     writer.startElement(HtmlElements.LI, null);
     if (component != null && !component.isTransient()) {
@@ -149,8 +140,15 @@ public class MenuCommandRenderer extends
         markup = Markup.TOP.add(markup);
       }
     }
-    writer.writeClassAttribute(Classes.createWorkaround("menu", markup)); // todo: solve
workaround
-    writer.writeAttribute(HtmlAttributes.ONCLICK, onclick, true);
+     // todo: solve workaround
+    String css = Classes.createWorkaround("menu", markup).getStringValue();
+    if (sub != null) {
+      css += " tobago-menu-" + sub;
+    }
+    writer.writeClassAttribute(css);
+    writer.writeAttribute(DataAttributes.COMMANDS, JsonUtils.encode(map), true);
+    writer.writeAttribute(DataAttributes.VALUE, value, true);
+
     if (component != null) {
       HtmlRendererUtils.writeDataAttributes(facesContext, writer, component);
     }

Modified: myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/util/JQueryUtils.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/util/JQueryUtils.java?rev=1466525&r1=1466524&r2=1466525&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/util/JQueryUtils.java
(original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/util/JQueryUtils.java
Wed Apr 10 15:42:22 2013
@@ -19,6 +19,10 @@
 
 package org.apache.myfaces.tobago.renderkit.util;
 
+/**
+ * @deprecated since 2.0.0. JavaScript should not be used no server side (CSP)
+ */
+@Deprecated
 public class JQueryUtils {
 
   private JQueryUtils() {

Modified: myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-menu.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-menu.js?rev=1466525&r1=1466524&r2=1466525&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-menu.js
(original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-menu.js
Wed Apr 10 15:42:22 2013
@@ -254,6 +254,22 @@ Tobago.Menu.init = function(elements) {
     event.stopPropagation();
   });
 
+  // selectOne
+  var selectOne = Tobago.Utils.selectWidthJQuery(elements, ".tobago-menu-selectOne");
+  selectOne.click(function() {
+    var menu = jQuery(this);
+    var hidden = menu.nextAll("input[type=hidden]").first();
+    hidden.val(menu.data("tobago-value"));
+  });
+
+  // selectBoolean
+  var selectBoolean = Tobago.Utils.selectWidthJQuery(elements, ".tobago-menu-selectBoolean");
+  selectBoolean.click(function() {
+    var menu = jQuery(this);
+    var hidden = menu.nextAll("input[type=hidden]").first();
+    hidden.val(hidden.val() == "true" ? "false" : "true");
+  });
+
   // IE6 select-tag fix
   // put a iframe inside the div, so that a <select> tag doesn't shine through.
   // the iframe must be resized (see above)

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=1466525&r1=1466524&r2=1466525&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
Wed Apr 10 15:42:22 2013
@@ -235,21 +235,21 @@ var Tobago = {
   initMarker: false,
 
   listeners: {
-    documentReady: [[], [], []],
-    windowLoad: [[], [], []],
-    beforeSubmit: [[], [], []],
-    afterUpdate: [[], [], []],
-    beforeUnload: [[], [], []],
-    beforeExit: [[], [], []]
+    documentReady: [[], [], [], []],
+    windowLoad: [[], [], [], []],
+    beforeSubmit: [[], [], [], []],
+    afterUpdate: [[], [], [], []],
+    beforeUnload: [[], [], [], []],
+    beforeExit: [[], [], [], []]
   },
 
   // -------- Functions -------------------------------------------------------
 
   /**
-   * Register a function to be excecuted on certain events.
+   * Register a function to be executed on certain events.
    * @param listener Function to be executed.
-   * @param phase The phase when code should be excecuted (e. g. Tobago.Phase.DOCUMENT_READY).
-   * @param order An optinal order to sort function they depent on others (default: Tobago.Phase.Order.NORMAL).
+   * @param phase The phase when code should be executed (e. g. Tobago.Phase.DOCUMENT_READY).
+   * @param order An optional order to sort function they depend on others (default: Tobago.Phase.Order.NORMAL).
    */
   registerListener: function(listener, phase, order) {
 
@@ -1682,7 +1682,8 @@ Tobago.Phase = {
   Order:{
     EARLY:0,
     NORMAL:1,
-    LATE:2
+    LATE:2,
+    LATER:3
   }
 };
 
@@ -1725,8 +1726,8 @@ Tobago.registerListener(Tobago.frameKill
 // using Tobago.Phase.Order.LATE, because the command event generated by data-tobago-commands
 // may produce a submit, but we need to do something before the submit (and also on click,
 // e. g. selectOne in a toolBar).
-Tobago.registerListener(Tobago.initDom, Tobago.Phase.DOCUMENT_READY, Tobago.Phase.Order.LATE);
-Tobago.registerListener(Tobago.initDom, Tobago.Phase.AFTER_UPDATE, Tobago.Phase.Order.LATE);
+Tobago.registerListener(Tobago.initDom, Tobago.Phase.DOCUMENT_READY, Tobago.Phase.Order.LATER);
+Tobago.registerListener(Tobago.initDom, Tobago.Phase.AFTER_UPDATE, Tobago.Phase.Order.LATER);
 
 // XXX: 2nd parameter enableAjax is deprecated
 Tobago.Panel = function(panelId, enableAjax, autoReload) {



Mime
View raw message