You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by hl...@apache.org on 2008/03/31 20:54:57 UTC

svn commit: r643098 - in /tapestry/tapestry5/trunk/tapestry-core/src: main/java/org/apache/tapestry/internal/services/ main/resources/org/apache/tapestry/ test/java/org/apache/tapestry/internal/services/ test/resources/

Author: hlship
Date: Mon Mar 31 11:54:53 2008
New Revision: 643098

URL: http://svn.apache.org/viewvc?rev=643098&view=rev
Log:
TAPESTRY-2319: Add support for client-side form-level validation

Modified:
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/RenderQueueImpl.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry/tapestry.js
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/RenderQueueImplTest.java
    tapestry/tapestry5/trunk/tapestry-core/src/test/resources/log4j.properties

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/RenderQueueImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/RenderQueueImpl.java?rev=643098&r1=643097&r2=643098&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/RenderQueueImpl.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/RenderQueueImpl.java Mon Mar 31 11:54:53 2008
@@ -49,6 +49,9 @@
 
         boolean traceEnabled = _logger.isTraceEnabled();
 
+        long startNanos = System.nanoTime();
+        int commandCount = 0;
+
         // Seems to make sense to use one try/finally around the whole process, rather than
         // around each call to render() since the end result (in a failure scenario) is the same.
 
@@ -58,6 +61,8 @@
             {
                 command = _queue.pop();
 
+                commandCount++;
+
                 if (traceEnabled) _logger.trace(String.format("Executing: %s", command));
 
                 command.render(writer, this);
@@ -74,6 +79,20 @@
 
             throw new RenderQueueException(message, _renderingComponents.getSnapshot(), ex);
         }
+
+        long endNanos = System.nanoTime();
+
+        if (_logger.isDebugEnabled())
+        {
+
+            long elapsedNanos = endNanos - startNanos;
+            double elapsedSeconds = ((float) elapsedNanos) / 1000000000F;
+
+            _logger.debug(String.format("Executed %,d rendering commands in %.2f seconds",
+                                        commandCount,
+                                        elapsedSeconds));
+        }
+
     }
 
     public void startComponent(ComponentResources resources)

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry/tapestry.js
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry/tapestry.js?rev=643098&r1=643097&r2=643098&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry/tapestry.js (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry/tapestry.js Mon Mar 31 11:54:53 2008
@@ -14,6 +14,10 @@
 
 var Tapestry = {
 
+    FORM_VALIDATE_EVENT : "form:validate",
+
+    FORM_PREPARE_FOR_SUBMIT_EVENT : "form:prepareforsubmit",
+
     FormEvent : Class.create(),
 
     FormEventManager : Class.create(),
@@ -258,12 +262,21 @@
 
     addValidator : function(field, acceptBlank, validator)
     {
+        this.getFieldEventManager(field).addValidator(acceptBlank, validator);
+    },
+
+    getFieldEventManager : function(field)
+    {
         field = $(field);
 
-        if (field.fieldEventManager == undefined) new Tapestry.FieldEventManager(field);
+        var manager = field.fieldEventManager;
 
-        field.fieldEventManager.addValidator(acceptBlank, validator);
+        if (manager == undefined) manager = new Tapestry.FieldEventManager(field);
+
+        return manager;
     }
+
+
 }
 
 
@@ -275,7 +288,7 @@
     // and its icon.
     decorateForValidationError : function (element, message)
     {
-        $(element).fieldEventManager.addDecorations(message);
+        Tapestry.getFieldEventManager(element).addDecorations(message);
     },
 
     // Checks to see if an element is truly visible, meaning the receiver and all
@@ -283,6 +296,8 @@
 
     isDeepVisible : function(element)
     {
+        element = $(element);
+
         if (! element.visible()) return false;
 
         // Stop at a form, which is sufficient for validation purposes.
@@ -393,6 +408,15 @@
 };
 
 Tapestry.ErrorPopup.prototype = {
+
+    BUBBLE_VERT_OFFSET : -34,
+
+    BUBBLE_HORIZONTAL_OFFSET : -5,
+
+    BUBBLE_WIDTH: "auto",
+
+    BUBBLE_HEIGHT: "39px",
+
     initialize : function(field)
     {
         this.field = $(field);
@@ -440,7 +464,11 @@
     {
         var fieldPos = this.field.positionedOffset();
 
-        this.outerDiv.setStyle({ top: fieldPos[1] - 34 + "px", left: fieldPos[0] - 5 + "px", width: "auto", height: "39px" });
+        this.outerDiv.setStyle({
+            top: (fieldPos[1] + this.BUBBLE_VERT_OFFSET) + "px",
+            left: (fieldPos[0] + this.BUBBLE_HORIZONTAL_OFFSET) + "px",
+            width: this.BUBBLE_WIDTH,
+            height: this.BUBBLE_HEIGHT });
     },
 
     fadeIn : function()
@@ -539,13 +567,20 @@
             }
         });
 
+        // Allow observers to validate the form as a whole.  The FormEvent will be visible
+        // as event.memo.  The Form will not be submitted if event.result is set to false (it defaults
+        // to true).
+
+        this.form.fire(Tapestry.FORM_VALIDATE_EVENT, event);
+
+
         if (! event.result)
         {
             domevent.stop();
         }
         else
         {
-            this.form.fire("form:prepareforsubmit");
+            this.form.fire(Tapestry.FORM_PREPARE_FOR_SUBMIT_EVENT);
         }
 
         return event.result;
@@ -766,7 +801,7 @@
         this.showFunc = Tapestry.ElementEffect[spec.show] || Tapestry.ElementEffect.slidedown;
         this.hideFunc = Tapestry.ElementEffect[spec.hide] || Tapestry.ElementEffect.slideup;
 
-        $(this.hidden.form).observe("form:prepareforsubmit", function()
+        $(this.hidden.form).observe(Tapestry.FORM_PREPARE_FOR_SUBMIT_EVENT, function()
         {
             this.hidden.value = this.element.isDeepVisible();
         }.bind(this));

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/RenderQueueImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/RenderQueueImplTest.java?rev=643098&r1=643097&r2=643098&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/RenderQueueImplTest.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/RenderQueueImplTest.java Mon Mar 31 11:54:53 2008
@@ -43,6 +43,7 @@
         // There's only one check for trace enabled now.
 
         train_isTraceEnabled(logger, false);
+        train_isDebugEnabled(logger, false);
 
         command2.render(writer, queue);
 
@@ -105,7 +106,7 @@
         {
             assertSame(ex.getCause(), t);
 
-            assertArraysEqual(ex.getActiveComponents(), new Object[]{foo, baz});
+            assertArraysEqual(ex.getActiveComponents(), new Object[] { foo, baz });
         }
 
         verify();

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/resources/log4j.properties
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/resources/log4j.properties?rev=643098&r1=643097&r2=643098&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/resources/log4j.properties (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/resources/log4j.properties Mon Mar 31 11:54:53 2008
@@ -21,7 +21,7 @@
 log4j.appender.A1.layout=org.apache.log4j.PatternLayout
 log4j.appender.A1.layout.ConversionPattern= %d{HH:mm:ss,SSS} [%p] %c{1} %m%n
 
-# log4j.category.org.apache.tapestry.corelib.pages=debug
+log4j.category.org.apache.tapestry.integration.app1=debug