myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lof...@apache.org
Subject svn commit: r1466486 - in /myfaces/tobago/trunk: tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/html/ tobago-example/tobago-example-test/src/main/webapp/test/toolBar/ tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces...
Date Wed, 10 Apr 2013 13:44:04 GMT
Author: lofwyr
Date: Wed Apr 10 13:44:04 2013
New Revision: 1466486

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

Modified:
    myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/html/DataAttributes.java
    myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/test/toolBar/toolBar.xhtml
    myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/ToolBarRendererBase.java
    myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/util/RenderUtils.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=1466486&r1=1466485&r2=1466486&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 13:44:04 2013
@@ -170,6 +170,11 @@ public final class DataAttributes {
   public static final String UNIT = "data-tobago-unit";
 
   /**
+   * Holds the value (for tags, that don't have a value in HTML).
+   */
+  public static final String VALUE = "data-tobago-value";
+
+  /**
    * Holds the year of a calendar control.
    */
   public static final String YEAR = "data-tobago-year";

Modified: myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/test/toolBar/toolBar.xhtml
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/test/toolBar/toolBar.xhtml?rev=1466486&r1=1466485&r2=1466486&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/test/toolBar/toolBar.xhtml
(original)
+++ myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/test/toolBar/toolBar.xhtml
Wed Apr 10 13:44:04 2013
@@ -27,9 +27,13 @@
     <f:facet name="layout">
       <tc:gridLayout
           columns="120px;*"
-          rows="auto;auto;auto;auto;auto;auto;auto;auto;auto;auto;auto;auto;auto;auto;auto;auto;70px;70px;auto;auto;auto;auto;auto;auto;auto;auto;auto;"/>
+          rows="auto;auto;auto;auto;auto;auto;auto;auto;auto;auto;auto;auto;auto;auto;auto;auto;auto;70px;70px;auto;auto;auto;auto;auto;auto;auto;auto;auto;"/>
     </f:facet>
 
+    <tc:messages>
+      <tc:gridLayoutConstraint columnSpan="2"/>
+    </tc:messages>
+
     <tc:separator label="Normal Tool Bar Commands">
       <tc:gridLayoutConstraint columnSpan="2"/>
     </tc:separator>

Modified: myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/ToolBarRendererBase.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/ToolBarRendererBase.java?rev=1466486&r1=1466485&r2=1466486&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/ToolBarRendererBase.java
(original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/ToolBarRendererBase.java
Wed Apr 10 13:44:04 2013
@@ -39,11 +39,13 @@ import org.apache.myfaces.tobago.renderk
 import org.apache.myfaces.tobago.renderkit.LayoutComponentRendererBase;
 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.RenderUtils;
 import org.apache.myfaces.tobago.util.ComponentUtils;
@@ -111,10 +113,9 @@ public abstract class ToolBarRendererBas
       } else if (command.getFacet(Facets.CHECKBOX) != null) {
         return renderSelectBoolean(facesContext, toolBar, command, writer, width);
       } else {
-        String onCommandClick = createCommandOnClick(facesContext, command);
-        String onMenuClick = createMenuOnClick(command);
+        final CommandMap map = hasAnyCommand(command) ? new CommandMap(new Command(facesContext,
command)) : null;
         return renderToolbarButton(
-            facesContext, toolBar, command, writer, false, onCommandClick, onMenuClick, width);
+            facesContext, toolBar, command, writer, false, width, map, null);
       }
     }
   }
@@ -124,12 +125,7 @@ public abstract class ToolBarRendererBas
   private Measure renderSelectOne(FacesContext facesContext, UIToolBar toolBar, AbstractUICommandBase
command,
       TobagoResponseWriter writer, Measure width) throws IOException {
 
-    String suffix = createCommandOnClick(facesContext, command);
-    if (suffix == null) {
-      suffix = "";
-    }
-
-    List<SelectItem> items;
+    final List<SelectItem> items;
 
     UIMenuSelectOne radio = (UIMenuSelectOne) command.getFacet(Facets.RADIO);
     if (radio == null) {
@@ -141,6 +137,8 @@ public abstract class ToolBarRendererBas
     }
 
     if (radio != null) {
+      writer.startElement(HtmlElements.SPAN, radio);
+      writer.writeClassAttribute(Classes.createWorkaround("toolBar", "selectOne", null));
       Object value = radio.getValue();
 
       String currentValue = "";
@@ -179,16 +177,17 @@ public abstract class ToolBarRendererBas
           checked = false;
         }
 
-        String onClick = "Tobago.ToolBar.setRadioValue('" + radioId + "', '" + formattedValue
+ "');" + suffix;
-        width = renderToolbarButton(facesContext, toolBar, command, writer, checked, onClick,
null, width);
+        final CommandMap map = new CommandMap(new Command());
+        width = renderToolbarButton(
+            facesContext, toolBar, command, writer, checked, width, map, formattedValue);
       }
 
       writer.startElement(HtmlElements.INPUT, null);
       writer.writeAttribute(HtmlAttributes.TYPE, HtmlInputTypes.HIDDEN, false);
-      writer.writeIdAttribute(radioId);
       writer.writeNameAttribute(radioId);
       writer.writeAttribute(HtmlAttributes.VALUE, currentValue, true);
       writer.endElement(HtmlElements.INPUT);
+      writer.endElement(HtmlElements.SPAN);
     }
     return width;
   }
@@ -207,20 +206,17 @@ public abstract class ToolBarRendererBas
     final boolean checked = ComponentUtils.getBooleanAttribute(checkbox, Attributes.VALUE);
     final String clientId = checkbox.getClientId(facesContext);
 
-    String onClick = createCommandOnClick(facesContext, command);
-    if (onClick == null) {
-      onClick = "";
-    }
-    onClick = "Tobago.ToolBar.checkToggle('" + clientId + "');" + onClick;
-
-    width = renderToolbarButton(facesContext, toolBar, command, writer, checked, onClick,
null, width);
+    writer.startElement(HtmlElements.SPAN, checkbox);
+    writer.writeClassAttribute(Classes.createWorkaround("toolBar", "selectBoolean", null));
+    final CommandMap map = new CommandMap(new Command());
+    width = renderToolbarButton(facesContext, toolBar, command, writer, checked, width, map,
null);
 
     writer.startElement(HtmlElements.INPUT, null);
     writer.writeAttribute(HtmlAttributes.TYPE, HtmlInputTypes.HIDDEN, false);
-    writer.writeIdAttribute(clientId);
     writer.writeNameAttribute(clientId);
     writer.writeAttribute(HtmlAttributes.VALUE, Boolean.toString(checked), false);
     writer.endElement(HtmlElements.INPUT);
+    writer.endElement(HtmlElements.SPAN);
 
     return width;
   }
@@ -228,7 +224,7 @@ public abstract class ToolBarRendererBas
 
   private Measure renderToolbarButton(
       FacesContext facesContext, UIToolBar toolBar, AbstractUICommandBase command, TobagoResponseWriter
writer,
-      boolean selected, String commandClick, String menuClick, Measure width)
+      boolean selected, Measure width, CommandMap map, String value)
       throws IOException {
     if (!command.isRendered()) {
       return width;
@@ -387,12 +383,24 @@ public abstract class ToolBarRendererBas
     writer.writeStyleAttribute(itemStyle);
 
     writer.startElement(HtmlElements.SPAN, command);
-    writer.writeClassAttribute(Classes.create(toolBar, "button", selected ? Markup.SELECTED
: Markup.NULL));
+    if (separateButtons || dropDownMenu == null) {
+      writer.writeClassAttribute(Classes.create(toolBar, "button", selected ? Markup.SELECTED
: Markup.NULL));
+    } else {
+      writer.writeClassAttribute(Classes.create(toolBar, "menu"));
+    }
     writer.writeStyleAttribute(buttonStyle);
     if (!toolBar.isTransient()) {
       writer.writeIdAttribute(command.getClientId(facesContext));
     }
-    writer.writeAttribute(HtmlAttributes.ONCLICK, commandClick != null ? commandClick : menuClick,
true);
+//    writer.writeAttribute(HtmlAttributes.ONCLICK, commandClick != null ? commandClick :
menuClick, true);
+    writer.writeAttribute(HtmlAttributes.ONCLICK, "/* dropped */", true);
+    if (map != null) {
+      writer.writeAttribute(DataAttributes.COMMANDS, JsonUtils.encode(map), true);
+    }
+    if (value != null) {
+      writer.writeAttribute(DataAttributes.VALUE, value, true);
+    }
+
     // render icon
     if (showIcon && iconName != null) {
       writer.startElement(HtmlElements.IMG, command);
@@ -426,7 +434,8 @@ public abstract class ToolBarRendererBas
       writer.writeStyleAttribute(menuStyle);
       // todo: span has not type: use data-tobago-type here (TOBAGO-1004)
       writer.writeAttribute(HtmlAttributes.TYPE, HtmlInputTypes.BUTTON, false);
-      writer.writeAttribute(HtmlAttributes.ONCLICK, menuClick, true);
+//      writer.writeAttribute(HtmlAttributes.ONCLICK, menuClick, true);
+      writer.writeAttribute(HtmlAttributes.ONCLICK, "/* dropped */", true);
     }
 
     // render sub menu popup button
@@ -510,15 +519,6 @@ public abstract class ToolBarRendererBas
     return result;
   }
 
-  private String createCommandOnClick(FacesContext facesContext, AbstractUICommandBase command)
{
-    if (hasNoCommand(command) && FacetUtils.getDropDownMenu(command) != null) {
-      return null;
-    } else {
-      CommandRendererHelper helper = new CommandRendererHelper(facesContext, command);
-      return helper.getOnclick();
-    }
-  }
-
   private boolean hasAnyCommand(AbstractUICommandBase command) {
     return !hasNoCommand(command);
   }
@@ -531,19 +531,6 @@ public abstract class ToolBarRendererBas
         && command.getAttributes().get(Attributes.ONCLICK) == null;
   }
 
-  private String createMenuOnClick(AbstractUICommandBase command) {
-    if (FacetUtils.getDropDownMenu(command) != null) {
-      return "jQuery(this).find('a').click(); " 
-          + "if (event.stopPropagation === undefined) { "
-          + "  event.cancelBubble = true; " // IE
-          + "} else { "
-          + "  event.stopPropagation(); " // other
-          + "}"; // todo: register a onclick handler with jQuery
-    } else {
-      return null;
-    }
-  }
-
   private String getImage(
       FacesContext facesContext, String name, String iconSize, boolean disabled, boolean
selected) {
     int pos = name.lastIndexOf('.');

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=1466486&r1=1466485&r2=1466486&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
Wed Apr 10 13:44:04 2013
@@ -24,7 +24,6 @@ import org.apache.myfaces.tobago.config.
 import org.apache.myfaces.tobago.context.ResourceManagerUtils;
 import org.apache.myfaces.tobago.internal.component.AbstractUICommandBase;
 import org.apache.myfaces.tobago.internal.component.AbstractUIData;
-import org.apache.myfaces.tobago.internal.component.AbstractUITree;
 import org.apache.myfaces.tobago.internal.util.StringUtils;
 import org.apache.myfaces.tobago.layout.Measure;
 import org.apache.myfaces.tobago.model.ExpandedState;
@@ -394,7 +393,7 @@ public class RenderUtils {
       final TreePath path = data.getPath();
 
       // selected
-        final SelectedState selectedState = ((AbstractUITree) data).getSelectedState();
+        final SelectedState selectedState = data.getSelectedState();
         final boolean oldSelected = selectedState.isSelected(path);
         final boolean newSelected = selectedIndices.contains(rowIndex);
         if (newSelected != oldSelected) {

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=1466486&r1=1466485&r2=1466486&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 13:44:04 2013
@@ -273,10 +273,10 @@ Tobago.Menu.init = function(elements) {
   jQuery(".tobago-page-menuStore").append(menus.children("ol"));
 
   var toolBarMenu = Tobago.Utils.selectWidthJQuery(
-      elements, ".tobago-toolBar-menu .tobago-boxToolBar-menu .tobago-tabGroupToolBar-menu");
+      elements, ".tobago-toolBar-menu, .tobago-boxToolBar-menu, .tobago-tabGroupToolBar-menu");
   // a click on toolBar menu opener -> forward to .tobago-menu-markup-top
   toolBarMenu.click(function(event) {
-    jQuery(this).next().find('a').click();
+    jQuery(this).find('a').click();
     event.stopPropagation();
   });
 

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=1466486&r1=1466485&r2=1466486&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 13:44:04 2013
@@ -1720,11 +1720,13 @@ Tobago.Config = {
   }
 };
 
-
 Tobago.Config.set("Tobago", "themeConfig", "standard/standard");
 Tobago.registerListener(Tobago.frameKiller, Tobago.Phase.DOCUMENT_READY);
-Tobago.registerListener(Tobago.initDom, Tobago.Phase.DOCUMENT_READY);
-Tobago.registerListener(Tobago.initDom, Tobago.Phase.AFTER_UPDATE);
+// 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);
 
 // XXX: 2nd parameter enableAjax is deprecated
 Tobago.Panel = function(panelId, enableAjax, autoReload) {
@@ -2466,13 +2468,33 @@ Tobago.ToolBar.init = function(elements)
         }
       });
     });
+
+  Tobago.Utils.selectWidthJQuery(elements, ".tobago-toolBar-selectOne").find(".tobago-toolBar-button")
+      .click(function () {
+        var button = jQuery(this);
+        var hidden = button.closest(".tobago-toolBar-selectOne").children("input[type=hidden]");
+        hidden.val(button.data("tobago-value"));
+      });
+
+  Tobago.Utils.selectWidthJQuery(elements, ".tobago-toolBar-selectBoolean").find(".tobago-toolBar-button")
+      .click(function () {
+        var button = jQuery(this);
+        var hidden = button.closest(".tobago-toolBar-selectBoolean").children("input[type=hidden]");
+        hidden.val(hidden.val() == "true" ? "false" : "true");
+      });
 };
 
+/**
+ * @deprecated since 2.0.0, use class tobago-toolBar-selectBoolean
+ */
 Tobago.ToolBar.checkToggle = function(id) {
   var element = document.getElementById(id);
   element.value = 'true' == element.value ? 'false' : 'true';
 };
 
+/**
+ * @deprecated since 2.0.0, use class tobago-toolBar-selectOne
+ */
 Tobago.ToolBar.setRadioValue = function(id, value) {
   var element = document.getElementById(id);
   element.value = value;



Mime
View raw message