tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject svn commit: r705756 - in /tapestry/tapestry5/trunk/tapestry-core/src: main/java/org/apache/tapestry5/corelib/components/ main/java/org/apache/tapestry5/corelib/internal/ main/java/org/apache/tapestry5/services/ test/java/org/apache/tapestry5/corelib/in...
Date Fri, 17 Oct 2008 21:15:54 GMT
Author: hlship
Date: Fri Oct 17 14:15:53 2008
New Revision: 705756

URL: http://svn.apache.org/viewvc?rev=705756&view=rev
Log:
TAP5-279: Client-side validation is always enabled for injected AjaxFormLoop fields

Added:
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/internal/InternalFormSupport.java
Modified:
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Form.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/FormInjector.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/internal/FormSupportAdapter.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/internal/FormSupportImpl.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/FormSupport.java
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/corelib/internal/FormSupportImplTest.java

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Form.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Form.java?rev=705756&r1=705755&r2=705756&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Form.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Form.java
Fri Oct 17 14:15:53 2008
@@ -18,6 +18,7 @@
 import org.apache.tapestry5.annotations.*;
 import org.apache.tapestry5.corelib.internal.ComponentActionSink;
 import org.apache.tapestry5.corelib.internal.FormSupportImpl;
+import org.apache.tapestry5.corelib.internal.InternalFormSupport;
 import org.apache.tapestry5.corelib.mixins.RenderInformals;
 import org.apache.tapestry5.dom.Element;
 import org.apache.tapestry5.internal.services.ClientBehaviorSupport;
@@ -30,6 +31,7 @@
 import org.apache.tapestry5.ioc.Messages;
 import org.apache.tapestry5.ioc.annotations.Inject;
 import org.apache.tapestry5.ioc.annotations.Symbol;
+import org.apache.tapestry5.ioc.internal.util.IdAllocator;
 import org.apache.tapestry5.ioc.internal.util.InternalUtils;
 import org.apache.tapestry5.ioc.internal.util.TapestryException;
 import org.apache.tapestry5.ioc.util.ExceptionUtils;
@@ -176,7 +178,7 @@
     @Inject
     private ComponentInvocationMap componentInvocationMap;
 
-    private FormSupportImpl formSupport;
+    private InternalFormSupport formSupport;
 
     private Element form;
 
@@ -228,8 +230,7 @@
 
         name = renderSupport.allocateClientId(resources);
 
-        formSupport = new FormSupportImpl(resources.getLocation(), name, actionSink, clientBehaviorSupport,
-                                          clientValidation);
+        formSupport = createRenderTimeFormSupport(name, actionSink, new IdAllocator());
 
         if (zone != null) clientBehaviorSupport.linkZone(name, zone);
 
@@ -287,6 +288,22 @@
         environment.peek(Heartbeat.class).begin();
     }
 
+    /**
+     * Creates an {@link org.apache.tapestry5.corelib.internal.InternalFormSupport} for this
Form. This method is used
+     * by {@link org.apache.tapestry5.corelib.components.FormInjector}.
+     *
+     * @param name       the client-side name and client id for the rendered form element
+     * @param actionSink used to collect component actions that will, ultimately, be written
as the t:formdata hidden
+     *                   field
+     * @param allocator  used to allocate unique ids
+     * @return form support object
+     */
+    InternalFormSupport createRenderTimeFormSupport(String name, ComponentActionSink actionSink,
IdAllocator allocator)
+    {
+        return new FormSupportImpl(resources, name, actionSink, clientBehaviorSupport,
+                                   clientValidation, allocator);
+    }
+
     void afterRender(MarkupWriter writer)
     {
         environment.peek(Heartbeat.class).end();
@@ -325,7 +342,7 @@
     {
         tracker.clear();
 
-        formSupport = new FormSupportImpl(resources.getLocation());
+        formSupport = new FormSupportImpl(resources);
 
         environment.push(ValidationTracker.class, tracker);
         environment.push(FormSupport.class, formSupport);

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/FormInjector.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/FormInjector.java?rev=705756&r1=705755&r2=705756&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/FormInjector.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/FormInjector.java
Fri Oct 17 14:15:53 2008
@@ -20,8 +20,8 @@
 import org.apache.tapestry5.annotations.SupportsInformalParameters;
 import org.apache.tapestry5.corelib.data.InsertPosition;
 import org.apache.tapestry5.corelib.internal.ComponentActionSink;
-import org.apache.tapestry5.corelib.internal.FormSupportImpl;
 import org.apache.tapestry5.corelib.internal.HiddenFieldPositioner;
+import org.apache.tapestry5.corelib.internal.InternalFormSupport;
 import org.apache.tapestry5.dom.Element;
 import org.apache.tapestry5.internal.services.ClientBehaviorSupport;
 import org.apache.tapestry5.internal.services.ComponentResultProcessorWrapper;
@@ -51,7 +51,9 @@
 {
     public static final String INJECT_EVENT = "inject";
 
-    public static final String FORMID_PARAMETER = "t:formid";
+    public static final String FORM_CLIENTID_PARAMETER = "t:formid";
+
+    public static final String FORM_COMPONENTID_PARAMETER = "t:formcomponentid";
 
     /**
      * The context for the link (optional parameter). This list of values will be converted
into strings and included in
@@ -113,6 +115,9 @@
     @Inject
     private Logger logger;
 
+    @Inject
+    private ComponentSource componentSource;
+
     private Element clientElement;
 
     String defaultElement()
@@ -135,7 +140,8 @@
         Link link = resources.createEventLink(INJECT_EVENT,
                                               context == null ? new Object[0] : context.toArray());
 
-        link.addParameter(FORMID_PARAMETER, formSupport.getClientId());
+        link.addParameter(FORM_CLIENTID_PARAMETER, formSupport.getClientId());
+        link.addParameter(FORM_COMPONENTID_PARAMETER, formSupport.getFormComponentId());
 
         clientBehaviorSupport.addFormInjector(clientId, link, position, show);
     }
@@ -186,12 +192,11 @@
 
         final RenderCommand rootRenderCommand = pageRenderQueue.getRootRenderCommand();
 
-        final String formId = request.getParameter(FORMID_PARAMETER);
+        final String formClientId = readParameterValue(FORM_CLIENTID_PARAMETER);
 
-        if (InternalUtils.isBlank(formId))
-            throw new RuntimeException(String.format(
-                    "Query parameter '%s' was blank, but should have been specified in the
request.",
-                    FORMID_PARAMETER));
+        String formComponentId = request.getParameter(FORM_COMPONENTID_PARAMETER);
+
+        final Form form = (Form) componentSource.getComponent(formComponentId);
 
         final ComponentActionSink actionSink = new ComponentActionSink(logger);
 
@@ -214,8 +219,8 @@
 
                 reply.put("elementId", clientId);
 
-                FormSupportImpl formSupport = new FormSupportImpl(null, formId, actionSink,
clientBehaviorSupport, true,
-                                                                  idAllocator);
+                InternalFormSupport formSupport =
+                        form.createRenderTimeFormSupport(formClientId, actionSink, idAllocator);
 
                 environment.push(FormSupport.class, formSupport);
                 environment.push(ValidationTracker.class, new ValidationTrackerImpl());
@@ -242,4 +247,16 @@
 
         pageRenderQueue.addPartialMarkupRendererFilter(filter);
     }
+
+    private String readParameterValue(String parameterName)
+    {
+        String value = request.getParameter(parameterName);
+
+        if (InternalUtils.isBlank(value))
+            throw new RuntimeException(String.format(
+                    "Query parameter '%s' was blank, but should have been specified in the
request.",
+                    parameterName));
+
+        return value;
+    }
 }

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/internal/FormSupportAdapter.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/internal/FormSupportAdapter.java?rev=705756&r1=705755&r2=705756&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/internal/FormSupportAdapter.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/internal/FormSupportAdapter.java
Fri Oct 17 14:15:53 2008
@@ -70,4 +70,9 @@
     {
         return delegate.isClientValidationEnabled();
     }
+
+    public String getFormComponentId()
+    {
+        return delegate.getFormComponentId();
+    }
 }

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/internal/FormSupportImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/internal/FormSupportImpl.java?rev=705756&r1=705755&r2=705756&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/internal/FormSupportImpl.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/internal/FormSupportImpl.java
Fri Oct 17 14:15:53 2008
@@ -15,14 +15,14 @@
 package org.apache.tapestry5.corelib.internal;
 
 import org.apache.tapestry5.ComponentAction;
+import org.apache.tapestry5.ComponentResources;
 import org.apache.tapestry5.Field;
 import org.apache.tapestry5.internal.services.ClientBehaviorSupport;
-import org.apache.tapestry5.ioc.BaseLocatable;
+import org.apache.tapestry5.ioc.Locatable;
 import org.apache.tapestry5.ioc.Location;
 import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
 import org.apache.tapestry5.ioc.internal.util.Defense;
 import org.apache.tapestry5.ioc.internal.util.IdAllocator;
-import org.apache.tapestry5.services.FormSupport;
 
 import java.util.List;
 
@@ -32,8 +32,10 @@
  * <p/>
  * TODO: Most methods should only be invokable depending on whether the form is rendering
or processing a submission.
  */
-public class FormSupportImpl extends BaseLocatable implements FormSupport
+public class FormSupportImpl implements InternalFormSupport, Locatable
 {
+    private final ComponentResources resources;
+
     private final ClientBehaviorSupport clientBehaviorSupport;
 
     private final boolean clientValidationEnabled;
@@ -50,33 +52,20 @@
 
     /**
      * Constructor used when processing a form submission.
-     *
-     * @param location
-     */
-    public FormSupportImpl(Location location)
-    {
-        this(location, null, null, null, false);
-    }
-
-    /**
-     * Constructor used when rendering.
      */
-    public FormSupportImpl(Location location, String clientId, ComponentActionSink actionSink,
-                           ClientBehaviorSupport clientBehaviorSupport,
-                           boolean clientValidationEnabled)
+    public FormSupportImpl(ComponentResources resources)
     {
-        this(location, clientId, actionSink, clientBehaviorSupport, clientValidationEnabled,
new IdAllocator());
+        this(resources, null, null, null, false, null);
     }
 
     /**
-     * Full constructor.
+     * Full constructor (specifically constructor for render time).
      */
-    public FormSupportImpl(Location location, String clientId, ComponentActionSink actionSink,
+    public FormSupportImpl(ComponentResources resources, String clientId, ComponentActionSink
actionSink,
                            ClientBehaviorSupport clientBehaviorSupport,
                            boolean clientValidationEnabled, IdAllocator idAllocator)
     {
-        super(location);
-
+        this.resources = resources;
         this.clientId = clientId;
         this.actionSink = actionSink;
         this.clientBehaviorSupport = clientBehaviorSupport;
@@ -84,9 +73,14 @@
         this.idAllocator = idAllocator;
     }
 
-    public String getFormId()
+    public Location getLocation()
     {
-        return clientId;
+        return resources.getLocation();
+    }
+
+    public String getFormComponentId()
+    {
+        return resources.getCompleteId();
     }
 
     public String allocateControlName(String id)

Added: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/internal/InternalFormSupport.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/internal/InternalFormSupport.java?rev=705756&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/internal/InternalFormSupport.java
(added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/internal/InternalFormSupport.java
Fri Oct 17 14:15:53 2008
@@ -0,0 +1,36 @@
+//  Copyright 2008 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package org.apache.tapestry5.corelib.internal;
+
+import org.apache.tapestry5.services.FormSupport;
+
+/**
+ * Additional methods for {@link org.apache.tapestry5.services.FormSupport} used internally
by Tapestry.
+ *
+ * @see org.apache.tapestry5.corelib.components.Form
+ * @see org.apache.tapestry5.corelib.components.FormInjector
+ */
+public interface InternalFormSupport extends FormSupport
+{
+    /**
+     * Executes any deferred callbacks added via {@link org.apache.tapestry5.services.FormSupport#defer(Runnable)}.
+     */
+    void executeDeferred();
+
+    /**
+     * Returns the form encoding type, if one has been set via a call to {@link org.apache.tapestry5.services.FormSupport#setEncodingType(String)}.
+     */
+    String getEncodingType();
+}

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/FormSupport.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/FormSupport.java?rev=705756&r1=705755&r2=705756&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/FormSupport.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/FormSupport.java
Fri Oct 17 14:15:53 2008
@@ -84,4 +84,10 @@
      * Return true if client validation is enabled for this form, false otherwise.
      */
     boolean isClientValidationEnabled();
+
+    /**
+     * Returns the complete id of the underlying Form component.  This is needed by {@link
+     * org.apache.tapestry5.corelib.components.FormInjector}.
+     */
+    String getFormComponentId();
 }

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/corelib/internal/FormSupportImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/corelib/internal/FormSupportImplTest.java?rev=705756&r1=705755&r2=705756&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/corelib/internal/FormSupportImplTest.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/corelib/internal/FormSupportImplTest.java
Fri Oct 17 14:15:53 2008
@@ -140,7 +140,7 @@
 
         replay();
 
-        FormSupportImpl support = new FormSupportImpl(null, null, null, clientBehaviorSupport,
true);
+        FormSupportImpl support = new FormSupportImpl(null, null, null, clientBehaviorSupport,
true, null);
 
         support.addValidation(barney, "required", "Who can live without Barney?", null);
 
@@ -155,7 +155,7 @@
 
         replay();
 
-        FormSupportImpl support = new FormSupportImpl(null, null, null, clientBehaviorSupport,
false);
+        FormSupportImpl support = new FormSupportImpl(null, null, null, clientBehaviorSupport,
false, null);
 
         support.addValidation(barney, "required", "Who can live without Barney?", null);
 



Mime
View raw message