You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by hl...@apache.org on 2008/08/21 01:15:31 UTC

svn commit: r687501 - in /tapestry/tapestry5/trunk/tapestry-core/src: main/java/org/apache/tapestry5/corelib/mixins/ main/java/org/apache/tapestry5/internal/ main/java/org/apache/tapestry5/services/ main/resources/org/apache/tapestry5/ test/app1/

Author: hlship
Date: Wed Aug 20 16:15:30 2008
New Revision: 687501

URL: http://svn.apache.org/viewvc?rev=687501&view=rev
Log:
TAPESTRY-2602: Error bubbles are in some cases placed incorrectly

Added:
    tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/spacer.gif   (with props)
Modified:
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/mixins/Autocomplete.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/DefaultValidationDecorator.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/default.css
    tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/tapestry.js
    tapestry/tapestry5/trunk/tapestry-core/src/test/app1/AutocompleteDemo.tml

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/mixins/Autocomplete.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/mixins/Autocomplete.java?rev=687501&r1=687500&r2=687501&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/mixins/Autocomplete.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/mixins/Autocomplete.java Wed Aug 20 16:15:30 2008
@@ -80,8 +80,8 @@
     private MarkupWriterFactory factory;
 
     @Inject
-    @Path("classpath:org/apache/tapestry5/ajax-loader.gif")
-    private Asset loader;
+    @Path("${tapestry.spacer-image}")
+    private Asset spacerImage;
 
     /**
      * Overwrites the default minimum characters to trigger a server round trip (the default is 1).
@@ -120,15 +120,14 @@
         String menuId = id + ":menu";
         String loaderId = id + ":loader";
 
-        // This image is made visible while the request is being processed.
-        // To be honest, I think Prototype hides it too soon, it should wait
-        // until the <div> is fully positioned and updated.
+        // The spacer image is used as a placeholder, allowing CSS to determine what image
+        // is actually displayed.
 
         writer.element("img",
 
-                       "src", loader.toClientURL(),
+                       "src", spacerImage.toClientURL(),
 
-                       "class", CSSClassConstants.INVISIBLE,
+                       "class", "t-autoloader-icon " + CSSClassConstants.INVISIBLE,
 
                        "id", loaderId);
         writer.end();

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/DefaultValidationDecorator.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/DefaultValidationDecorator.java?rev=687501&r1=687500&r2=687501&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/DefaultValidationDecorator.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/DefaultValidationDecorator.java Wed Aug 20 16:15:30 2008
@@ -27,7 +27,7 @@
 {
     private final Environment environment;
 
-    private final Asset iconAsset;
+    private final Asset spacerAsset;
 
     private final Messages validationMessages;
 
@@ -37,15 +37,15 @@
      * @param environment        used to locate objects and services during the render
      * @param validationMessages obtained from {@link org.apache.tapestry5.services.ValidationMessagesSource}, used to
      *                           obtain the label for the icon
-     * @param iconAsset          asset for an icon that will be displayed after each field (marked with the
+     * @param spacerAsset        asset for a one-pixel spacer image used as a placeholder for the error marker icon
      * @param markupWriter
      */
-    public DefaultValidationDecorator(Environment environment, Messages validationMessages, Asset iconAsset,
+    public DefaultValidationDecorator(Environment environment, Messages validationMessages, Asset spacerAsset,
                                       MarkupWriter markupWriter)
     {
         this.environment = environment;
         this.validationMessages = validationMessages;
-        this.iconAsset = iconAsset;
+        this.spacerAsset = spacerAsset;
         this.markupWriter = markupWriter;
     }
 
@@ -63,12 +63,21 @@
         if (inError(field)) element.addClassName(CSSClassConstants.ERROR);
     }
 
+    /**
+     * Writes an icon for field after the field.  The icon has the same id as the field, with ":icon" appended. This is
+     * expected by the default client-side JavaScript.  The icon's src is a blank spacer image (this is to allow the
+     * image displayed to be overridden via CSS).     The icon's CSS class is "t-error-icon", with "t-invisible" added
+     * if the field is not in error when rendered.  If client validation is not enabled for the form containing the
+     * field and the field is not in error, then the error icon itself is not rendered.
+     *
+     * @param field which just completed rendering itself
+     */
     @Override
     public void afterField(Field field)
     {
         boolean inError = inError(field);
 
-        boolean clientValidationEnabled = environment.peekRequired(FormSupport.class).isClientValidationEnabled();
+        boolean clientValidationEnabled = getFormSupport().isClientValidationEnabled();
 
         if (inError || clientValidationEnabled)
         {
@@ -78,7 +87,7 @@
 
             markupWriter.element("img",
 
-                                 "src", iconAsset.toClientURL(),
+                                 "src", spacerAsset.toClientURL(),
 
                                  "alt", "",
 
@@ -90,6 +99,11 @@
 
     }
 
+    private FormSupport getFormSupport()
+    {
+        return environment.peekRequired(FormSupport.class);
+    }
+
     private boolean inError(Field field)
     {
         ValidationTracker tracker = environment.peekRequired(ValidationTracker.class);

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java?rev=687501&r1=687500&r2=687501&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java Wed Aug 20 16:15:30 2008
@@ -1429,8 +1429,8 @@
                                          @Path("${tapestry.default-stylesheet}")
                                          final Asset stylesheetAsset,
 
-                                         @Path("${tapestry.field-error-marker}")
-                                         final Asset fieldErrorIcon,
+                                         @Path("${tapestry.spacer-image}")
+                                         final Asset spacerImage,
 
                                          final ValidationMessagesSource validationMessagesSource,
 
@@ -1512,7 +1512,7 @@
             {
                 Messages messages = validationMessagesSource.getValidationMessages(threadLocale.getLocale());
 
-                ValidationDecorator decorator = new DefaultValidationDecorator(environment, messages, fieldErrorIcon,
+                ValidationDecorator decorator = new DefaultValidationDecorator(environment, messages, spacerImage,
                                                                                writer);
 
                 environment.push(ValidationDecorator.class, decorator);
@@ -1544,8 +1544,8 @@
      */
     public void contributePartialMarkupRenderer(OrderedConfiguration<PartialMarkupRendererFilter> configuration,
 
-                                                @Path("${tapestry.field-error-marker}")
-                                                final Asset fieldErrorIcon,
+                                                @Path("${tapestry.spacer-image}")
+                                                final Asset spacerImage,
 
                                                 final SymbolSource symbolSource,
 
@@ -1622,7 +1622,7 @@
             {
                 Messages messages = validationMessagesSource.getValidationMessages(threadLocale.getLocale());
 
-                ValidationDecorator decorator = new DefaultValidationDecorator(environment, messages, fieldErrorIcon,
+                ValidationDecorator decorator = new DefaultValidationDecorator(environment, messages, spacerImage,
                                                                                writer);
 
                 environment.push(ValidationDecorator.class, decorator);
@@ -1770,8 +1770,8 @@
 
         configuration.add("tapestry.start-page-name", "start");
 
-        configuration.add("tapestry.default-stylesheet", "org/apache/tapestry5/default.css");
-        configuration.add("tapestry.field-error-marker", "org/apache/tapestry5/field-error-marker.gif");
+        configuration.add("tapestry.default-stylesheet", "classpath:/org/apache/tapestry5/default.css");
+        configuration.add("tapestry.spacer-image", "classpath:/org/apache/tapestry5/spacer.gif");
 
         configuration.add("tapestry.page-pool.soft-limit", "5");
         configuration.add("tapestry.page-pool.soft-wait", "10 ms");

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/default.css
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/default.css?rev=687501&r1=687500&r2=687501&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/default.css (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/default.css Wed Aug 20 16:15:30 2008
@@ -44,6 +44,16 @@
 
 IMG.t-error-icon {
     margin-left: 4px;
+    width: 16px;
+    height: 16px;
+    background: url( field-error-marker.gif );
+}
+
+IMG.t-autoloader-icon {
+    margin-left: 4px;
+    width: 16px;
+    heigth: 16px;
+    background: url( ajax-loader.gif );
 }
 
 IMG.t-sort-icon {

Added: tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/spacer.gif
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/spacer.gif?rev=687501&view=auto
==============================================================================
Binary file - no diff available.

Propchange: tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/spacer.gif
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/tapestry.js
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/tapestry.js?rev=687501&r1=687500&r2=687501&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/tapestry.js (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/tapestry.js Wed Aug 20 16:15:30 2008
@@ -721,7 +721,7 @@
 
     repositionBubble : function()
     {
-        var fieldPos = this.field.positionedOffset();
+        var fieldPos = this.field.cumulativeOffset();
 
         this.outerDiv.setStyle({
             top: (fieldPos[1] + this.BUBBLE_VERT_OFFSET) + "px",
@@ -947,7 +947,7 @@
 
                 validator(value, event);
 
-     // event.error is set by Tapestry.FormEvent.recordError().
+                // event.error is set by Tapestry.FormEvent.recordError().
 
                 if (event.error) throw $break;
             }
@@ -1124,7 +1124,7 @@
                 // before or after the FormInjector's element.
 
                 var newElement = new Element(this.element.tagName, { 'class' : this.element.className });
-                
+
                 // Insert the new element before or after the existing element.
 
                 var param = { };

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/app1/AutocompleteDemo.tml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/app1/AutocompleteDemo.tml?rev=687501&r1=687500&r2=687501&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/app1/AutocompleteDemo.tml (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/app1/AutocompleteDemo.tml Wed Aug 20 16:15:30 2008
@@ -7,7 +7,7 @@
         <div class="t-beaneditor">
             <div class="t-beaneditor-row">
                 <t:label for="title"/>
-                <t:textfield t:id="title" t:mixins="autocomplete" tokens=",;" size="100"/>
+                <t:textfield t:id="title" t:mixins="autocomplete" tokens=",;" size="60"/>
             </div>
 
             <div class="t-beaneditor-row">