tapestry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject svn commit: r600027 - in /tapestry/tapestry5/trunk/tapestry-core/src/main: java/org/apache/tapestry/corelib/components/Palette.java java/org/apache/tapestry/json/JSONArray.java resources/org/apache/tapestry/corelib/components/palette.js
Date Sat, 01 Dec 2007 00:54:21 GMT
Author: hlship
Date: Fri Nov 30 16:54:19 2007
New Revision: 600027

URL: http://svn.apache.org/viewvc?rev=600027&view=rev
Log:
TAPESTRY-1838: Palette javascript Error when an item contains a quote

Modified:
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/Palette.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/json/JSONArray.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry/corelib/components/palette.js

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/Palette.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/Palette.java?rev=600027&r1=600026&r2=600027&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/Palette.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/Palette.java
Fri Nov 30 16:54:19 2007
@@ -22,7 +22,7 @@
 import org.apache.tapestry.internal.util.SelectModelRenderer;
 import org.apache.tapestry.ioc.annotations.Inject;
 import static org.apache.tapestry.ioc.internal.util.CollectionFactory.*;
-import org.apache.tapestry.ioc.internal.util.InternalUtils;
+import org.apache.tapestry.json.JSONArray;
 import org.apache.tapestry.services.Request;
 
 import java.util.Collections;
@@ -282,7 +282,8 @@
     @Override
     protected void processSubmission(String elementName)
     {
-        String values = _request.getParameter(elementName + ":values");
+        String parameterValue = _request.getParameter(elementName + ":values");
+        JSONArray values = new JSONArray(parameterValue);
 
         // Use a couple of local variables to cut down on access via bindings
 
@@ -293,14 +294,15 @@
 
         ValueEncoder encoder = _encoder;
 
-        if (InternalUtils.isNonBlank(values))
+
+        int count = values.length();
+        for (int i = 0; i < count; i++)
         {
-            for (String value : values.split(";"))
-            {
-                Object objectValue = encoder.toValue(value);
+            String value = values.getString(i);
 
-                selected.add(objectValue);
-            }
+            Object objectValue = encoder.toValue(value);
+
+            selected.add(objectValue);
         }
 
         _selected = selected;
@@ -313,8 +315,7 @@
 
     void beginRender(MarkupWriter writer)
     {
-        String sep = "";
-        StringBuilder selectedValues = new StringBuilder();
+        JSONArray selectedValues = new JSONArray();
 
         for (OptionModel selected : _selectedOptions)
         {
@@ -322,26 +323,21 @@
             Object value = selected.getValue();
             String clientValue = _encoder.toClient(value);
 
-            selectedValues.append(sep);
-            selectedValues.append(clientValue);
-
-            sep = ";";
+            selectedValues.put(clientValue);
         }
 
-        StringBuilder naturalOrder = new StringBuilder();
-        sep = "";
+        JSONArray naturalOrder = new JSONArray();
+
         for (String value : _naturalOrder)
         {
-            naturalOrder.append(sep);
-            naturalOrder.append(value);
-            sep = ";";
+            naturalOrder.put(value);
         }
 
         String clientId = getClientId();
 
         _renderSupport.addScriptLink(_paletteLibrary);
 
-        _renderSupport.addScript("new Tapestry.Palette('%s', %s, '%s');", clientId, _reorder,
naturalOrder);
+        _renderSupport.addScript("new Tapestry.Palette('%s', %s, %s);", clientId, _reorder,
naturalOrder);
 
         writer.element("input", "type", "hidden", "id", clientId + ":values", "name", getElementName()
+ ":values",
                        "value", selectedValues);

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/json/JSONArray.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/json/JSONArray.java?rev=600027&r1=600026&r2=600027&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/json/JSONArray.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/json/JSONArray.java
Fri Nov 30 16:54:19 2007
@@ -98,6 +98,13 @@
     {
     }
 
+    public JSONArray(String text)
+    {
+        JSONTokener tokener = new JSONTokener(text);
+
+        parse(tokener);
+    }
+
     /**
      * Construct a JSONArray from a JSONTokener.
      *
@@ -108,6 +115,11 @@
     {
         assert tokenizer != null;
 
+        parse(tokenizer);
+    }
+
+    private void parse(JSONTokener tokenizer)
+    {
         if (tokenizer.nextClean() != '[')
         {
             throw tokenizer

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry/corelib/components/palette.js
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry/corelib/components/palette.js?rev=600027&r1=600026&r2=600027&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry/corelib/components/palette.js
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry/corelib/components/palette.js
Fri Nov 30 16:54:19 2007
@@ -2,6 +2,9 @@
 
 Tapestry.Palette.prototype = {
 
+    // id: of main select element
+    // reorder: true to enable extra controls for changing selection order
+    // naturalOrder: array of values, the proper order for the elements (needed when de-selecting
items)
     initialize : function(id, reorder, naturalOrder)
     {
         this.reorder = reorder;
@@ -12,9 +15,6 @@
 
         this.hidden = $(id + ":values");
 
-	  // Seperator used for values in the hidden field.
-        this.sep = ";";
-
 	  // The BUTTON elements
         this.select = $(id + ":select");
         this.deselect = $(id + ":deselect");
@@ -27,7 +27,7 @@
 
         this.valueToOrderIndex = {};
 
-        naturalOrder.split(this.sep).each(function (value, i)
+        naturalOrder.each(function (value, i)
         {
             this.valueToOrderIndex[value] = i;
         }.bind(this));
@@ -38,21 +38,21 @@
     bindEvents : function()
     {
         var updateButtons = this.updateButtons.bindAsEventListener(this);
-        Event.observe(this.avail, "change", updateButtons);
-        Event.observe(this.selected, "change", updateButtons);
+        this.avail.observe("change", updateButtons);
+        this.selected.observe("change", updateButtons);
 
         var selectClicked = this.selectClicked.bindAsEventListener(this);
-        Event.observe(this.select, "click", selectClicked);
-        Event.observe(this.avail, "dblclick", selectClicked);
+        this.select.observe("click", selectClicked);
+        this.avail.observe("dblclick", selectClicked);
 
         var deselectClicked = this.deselectClicked.bindAsEventListener(this);
-        Event.observe(this.deselect, "click", deselectClicked);
-        Event.observe(this.selected, "dblclick", deselectClicked);
+        this.deselect.observe("click", deselectClicked);
+        this.selected.observe("dblclick", deselectClicked);
 
         if (this.reorder)
         {
-            Event.observe(this.up, "click", this.moveUpClicked.bindAsEventListener(this));
-            Event.observe(this.down, "click", this.moveDownClicked.bindAsEventListener(this));
+            this.up.observe("click", this.moveUpClicked.bindAsEventListener(this));
+            this.down.observe("click", this.moveDownClicked.bindAsEventListener(this));
         }
     },
 
@@ -140,7 +140,7 @@
             return o.value;
         });
 
-        this.hidden.value = values.join(this.sep);
+        this.hidden.value = values.toJSON();
     },
 
     moveUpClicked : function(event)



Mime
View raw message