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 2010/02/05 19:56:41 UTC
svn commit: r907055 - in /tapestry/tapestry5/trunk: src/site/apt/
tapestry-core/src/main/java/org/apache/tapestry5/
tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/
tapestry-core/src/main/resources/org/apache/tapestry5/ tapestry-cor...
Author: hlship
Date: Fri Feb 5 18:56:40 2010
New Revision: 907055
URL: http://svn.apache.org/viewvc?rev=907055&view=rev
Log:
TAP5-86: Add support for "cancel" submit buttons (which bypass client-side validation)
Modified:
tapestry/tapestry5/trunk/src/site/apt/index.apt
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/EventConstants.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/RenderSupport.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/BeanEditForm.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Submit.java
tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/BeanEditForm.properties
tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/BeanEditForm.tml
tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/tapestry.js
tapestry/tapestry5/trunk/tapestry-core/src/test/app1/BeanEditorDemo.tml
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/FormTests.java
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/BeanEditorDemo.java
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/ValidBeanEditorDemo.java
Modified: tapestry/tapestry5/trunk/src/site/apt/index.apt
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/src/site/apt/index.apt?rev=907055&r1=907054&r2=907055&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/src/site/apt/index.apt (original)
+++ tapestry/tapestry5/trunk/src/site/apt/index.apt Fri Feb 5 18:56:40 2010
@@ -34,12 +34,15 @@
New And Of Note
+ * Submit components can now be used to cancel a form (bypassing client-side validation).
+
* Tapestry no longer uses a StAX parser to parse templates (it uses a standard SAX parser), meaning fewer dependencies and
better compatibility with Google App Engine.
* A {{{guide/testing.html}guide to integration testing}} is now available.
- * The annotated {{{guide/persist.html}@SessionAttribute}} can be used to read or to write some data from or into the HttpSession.
+ * The {{{guide/persist.html}@SessionAttribute}} annotation can be used on component fields to
+ read write HttpSession attributes.
* The {{{tapestry-beanvalidator}JSR-303 Integration Library}} is now available.
@@ -101,7 +104,7 @@
}
}
- Object onSuccess()
+ Object onSuccessFromForm()
{
return PostLogin.class;
}
@@ -109,9 +112,9 @@
}
+----+
- This short snippet demonstrates a bit about how Tapestry operates. Pages and services
+ This short snippet demonstrates a bit about how Tapestry operates. Services
within the application are injected with the @Inject annotation. The method names, onValidateFromForm()
- and onSuccess(),
+ and onSuccessFromForm(),
inform Tapestry about when the method is to be invoked. The two events <validate> and <success> occur
when a form is submitted; "validate" is triggered to perform cross-field validations, and "success" is
only triggered when there are no validation errors. The onSuccess() method's
@@ -122,18 +125,19 @@
This also represents a distinct change from Tapestry 4. In earlier versions of Tapestry,
the Form component's listener parameter would be bound to the method to invoke, by name. Further,
the listener method had to be public.
- This new approach not only support multiple listeners, but provides an improved separation of
- view concerns (inside the page's HTML template) and logic concerns, inside the Java class.
+ This new approach not only supports multiple listeners, but provides an improved separation of
+ view concerns (inside the page's template) and logic concerns, inside the Java class.
In many cases, additional information about the event is available, and can be passed
into the method by adding parameters to the method. Again, Tapestry will adapt
- to your parameters, in whatever order you supply them.
+ to your parameters.
Tapestry also saves you effort: the @Property annotation marks a field as readable and writable;
- Tapestry will provide the accessor methods automatically.
+ Tapestry will provide the accessor methods automatically. This kind of meta-programming is common in Tapestry,
+ and easy to implement yourself.
Finally, Tapestry 5 explicitly separates actions (requests that change things) and rendering (requests that
- render pages) into two separate requests. Performing an action, such as clicking a link or submitting a form,
+ render pages into markup) into two separate requests. Performing an action, such as clicking a link or submitting a form,
results in a <client side redirect> to the new page. This is often called "redirect after post". This helps ensure
that URLs in the browser are book-markable ... but also requires that a bit more information be stored in the session
between requests (using the @Persist annotation).
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/EventConstants.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/EventConstants.java?rev=907055&r1=907054&r2=907055&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/EventConstants.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/EventConstants.java Fri Feb 5 18:56:40 2010
@@ -14,6 +14,8 @@
package org.apache.tapestry5;
+import org.apache.tapestry5.corelib.components.BeanEditForm;
+
/**
* Constant values for common event names fired by Tapestry components.
*/
@@ -74,16 +76,22 @@
/**
* Event type for a notification to perform validation of submitted data. This allows a listener
* to perform
- * cross-field validation. This occurs before the {@link #SUCCESS} or {@link #FAILURE}
- * notification.
+ * cross-field validation. This occurs before the {@link #SUCCESS} or {@link #FAILURE} notification.
*
* @see org.apache.tapestry5.corelib.components.Form
- * @deprecated As of 5.2, this event should no longer be used; the Form component now fires a
- * {@link #VALIDATE} event.
+ * @deprecated As of 5.2, this event should no longer be used; the Form component now fires a {@link #VALIDATE}
+ * event.
*/
public static final String VALIDATE_FORM = "validateForm";
/**
+ * Event type associated with clicking the cancel button inside a {@link BeanEditForm}.
+ *
+ * @since 5.2.0
+ */
+ public static final String CANCELED = "canceled";
+
+ /**
* Event type for a notification after the form has submitted, when there are no errors in the
* validation tracker.
* This occurs before the {@link #SUBMIT} event.
@@ -107,7 +115,7 @@
public static final String SELECTED = "selected";
/**
- * Event triggered by some form-related cmponents to parse a value provided by the client. This
+ * Event triggered by some form-related components to parse a value provided by the client. This
* takes the place of a {@link org.apache.tapestry5.Translator}.
*/
public static final String PARSE_CLIENT = "parseClient";
@@ -154,8 +162,7 @@
public static final String SYNCHRONIZE_VALUES = "synchronizeValues";
/**
- * Event triggered by {@link org.apache.tapestry5.corelib.components.ProgressiveDisplay}
- * component to inform its
+ * Event triggered by {@link org.apache.tapestry5.corelib.components.ProgressiveDisplay} component to inform its
* container of what context (if any) is available. The event handler may return a renderable
* object or null. If
* null is returned, the component renders its own body as the partial markup response.
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/RenderSupport.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/RenderSupport.java?rev=907055&r1=907054&r2=907055&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/RenderSupport.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/RenderSupport.java Fri Feb 5 18:56:40 2010
@@ -175,7 +175,8 @@
* the name of the function (on the client-side Tapestry object) to invoke.
* @param parameters
* @deprecated Use {@link JavascriptSupport#addInitializerCall(String, JSONObject)} instead (which may require
- * changes to your JavaScript initializer function)
+ * changes to your JavaScript initializer function), or (for a single parameter)
+ * {@link JavascriptSupport#addInitializerCall(String, String)}
*/
void addInit(String functionName, String... parameters);
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/BeanEditForm.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/BeanEditForm.java?rev=907055&r1=907054&r2=907055&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/BeanEditForm.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/BeanEditForm.java Fri Feb 5 18:56:40 2010
@@ -1,10 +1,10 @@
-// Copyright 2007, 2008, 2009 The Apache Software Foundation
+// Copyright 2007, 2008, 2009, 2010 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
+// 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,
@@ -14,12 +14,16 @@
package org.apache.tapestry5.corelib.components;
+import java.io.IOException;
+
import org.apache.tapestry5.*;
import org.apache.tapestry5.annotations.*;
import org.apache.tapestry5.beaneditor.BeanModel;
import org.apache.tapestry5.internal.beaneditor.BeanModelUtils;
+import org.apache.tapestry5.internal.services.ComponentResultProcessorWrapper;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.services.BeanModelSource;
+import org.apache.tapestry5.services.ComponentEventResultProcessor;
/**
* A component that creates an entire form editing the properties of a particular bean. Inspired by <a
@@ -36,7 +40,7 @@
* <p/>
* BeanEditForm contains a {@link org.apache.tapestry5.corelib.components.Form} component and will trigger all the
* events of a Form.
- *
+ *
* @see org.apache.tapestry5.beaneditor.BeanModel
* @see org.apache.tapestry5.services.BeanModelSource
* @see org.apache.tapestry5.corelib.components.PropertyEditor
@@ -58,14 +62,15 @@
* The object to be edited. This will be read when the component renders and updated when the form for the component
* is submitted. Typically, the container will listen for a "prepare" event, in order to ensure that a non-null
* value is ready to be read or updated. Often, the BeanEditForm can create the object as needed (assuming a public,
- * no arguments constructor). The object property defaults to a property with the same name as the component id.
+ * no arguments constructor). The object property defaults to a property with the same name as the component id.
*/
@Parameter(required = true, autoconnect = true)
@Property
private Object object;
/**
- * A comma-separated list of property names to be retained from the {@link org.apache.tapestry5.beaneditor.BeanModel}.
+ * A comma-separated list of property names to be retained from the
+ * {@link org.apache.tapestry5.beaneditor.BeanModel}.
* Only these properties will be retained, and the properties will also be reordered. The names are
* case-insensitive.
*/
@@ -80,7 +85,8 @@
private String add;
/**
- * A comma-separated list of property names to be removed from the {@link org.apache.tapestry5.beaneditor.BeanModel}.
+ * A comma-separated list of property names to be removed from the {@link org.apache.tapestry5.beaneditor.BeanModel}
+ * .
* The names are case-insensitive.
*/
@SuppressWarnings("unused")
@@ -96,11 +102,21 @@
@Parameter(defaultPrefix = BindingConstants.LITERAL)
private String reorder;
- @Component(parameters =
- "validationId=componentResources.id", publishParameters = "clientValidation,autofocus,zone")
+ @Component(parameters = "validationId=componentResources.id", publishParameters = "clientValidation,autofocus,zone")
private Form form;
/**
+ * If set to true, then the form will include an additional button after the submit button labeled "Cancel".
+ * The cancel button will submit the form, bypassing client-side validation. The BeanEditForm will fire a
+ * {@link EventConstants#CANCELED} event (before the form's {@link EventConstants#VALIDATE} event).
+ *
+ * @since 5.2.0
+ */
+ @Property
+ @Parameter
+ private boolean cancel;
+
+ /**
* The model that identifies the parameters to be edited, their order, and every other aspect. If not specified, a
* default bean model will be created from the type of the object bound to the object parameter.
*/
@@ -115,6 +131,12 @@
@Inject
private BeanModelSource beanModelSource;
+ /**
+ * Set up via the traditional or Ajax component event request handler
+ */
+ @SuppressWarnings("unchecked")
+ @Environmental
+ private ComponentEventResultProcessor componentEventResultProcessor;
void onPrepareFromForm()
{
@@ -130,7 +152,6 @@
BeanModelUtils.modify(model, add, include, exclude, reorder);
}
-
/**
* Returns the client id of the embedded form.
*/
@@ -163,4 +184,13 @@
{
form.recordError(errorMessage);
}
+
+ boolean onSelectedFromCancel() throws IOException
+ {
+ ComponentResultProcessorWrapper callback = new ComponentResultProcessorWrapper(componentEventResultProcessor);
+
+ resources.triggerEvent(EventConstants.CANCELED, null, callback);
+
+ return callback.isAborted();
+ }
}
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Submit.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Submit.java?rev=907055&r1=907054&r2=907055&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Submit.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Submit.java Fri Feb 5 18:56:40 2010
@@ -1,10 +1,10 @@
-// Copyright 2007, 2008, 2009 The Apache Software Foundation
+// Copyright 2007, 2008, 2009, 2010 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
+// 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,
@@ -19,11 +19,13 @@
import org.apache.tapestry5.annotations.Events;
import org.apache.tapestry5.annotations.Parameter;
import org.apache.tapestry5.annotations.SupportsInformalParameters;
+import org.apache.tapestry5.corelib.SubmitMode;
import org.apache.tapestry5.dom.Element;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.services.FormSupport;
import org.apache.tapestry5.services.Heartbeat;
import org.apache.tapestry5.services.Request;
+import org.apache.tapestry5.services.javascript.JavascriptSupport;
/**
* Corresponds to <input type="submit"> or <input type="image">, a client-side element that can force the
@@ -43,7 +45,7 @@
/**
* The name of the event that will be triggered if this component is the cause of the form submission. The default
- * is "selected".
+ * is {@link EventConstants#SELECTED}.
*/
@Parameter(allowNull = false, defaultPrefix = BindingConstants.LITERAL)
private String event = EventConstants.SELECTED;
@@ -58,7 +60,7 @@
/**
* The list of values that will be made available to event handler method of this component when the form is
* submitted.
- *
+ *
* @since 5.1.0.0
*/
@Parameter
@@ -66,12 +68,21 @@
/**
* If provided, the component renders an input tag with type "image". Otherwise "submit".
- *
+ *
* @since 5.1.0.0
*/
@Parameter(defaultPrefix = BindingConstants.ASSET)
private Asset image;
+ /**
+ * Defines the mode, or client-side behavior, for the submit. The default is {@link SubmitMode#NORMAL}; clicking the
+ * button submits the form with validation. {@link SubmitMode#CANCEL} indicates the client-side validation
+ * should be omitted (though server-side validation still occurs).
+ *
+ * @since 5.2.0
+ */
+ @Parameter(allowNull = false, defaultPrefix = BindingConstants.LITERAL)
+ private SubmitMode mode = SubmitMode.NORMAL;
@Environmental
private FormSupport formSupport;
@@ -86,7 +97,7 @@
private Request request;
@Inject
- private RenderSupport renderSupport;
+ private JavascriptSupport javascriptSupport;
private Element element;
@@ -128,9 +139,11 @@
element = writer.element("input", "type", type, "name", name);
- if (disabled) writer.attributes("disabled", "disabled");
+ if (disabled)
+ writer.attributes("disabled", "disabled");
- if (image != null) writer.attributes("src", image.toClientURL());
+ if (image != null)
+ writer.attributes("src", image.toClientURL());
formSupport.store(this, new ProcessSubmission(name));
@@ -140,15 +153,20 @@
void afterRender(MarkupWriter writer)
{
writer.end();
+
+ if (mode == SubmitMode.CANCEL)
+ javascriptSupport.addInitializerCall("cancelButton", getClientId());
}
void processSubmission(String elementName)
{
- if (disabled) return;
+ if (disabled)
+ return;
String value = request.getParameter(image == null ? elementName : elementName + ".x");
- if (value == null) return;
+ if (value == null)
+ return;
Runnable sendNotification = new Runnable()
{
@@ -162,21 +180,23 @@
// heartbeat). This is most likely because the Submit is inside a Loop and some contextual
// information will change if we defer.
- if (defer) formSupport.defer(sendNotification);
- else heartbeat.defer(sendNotification);
+ if (defer)
+ formSupport.defer(sendNotification);
+ else
+ heartbeat.defer(sendNotification);
}
/**
* Returns the component's client id. This must be called after the component has rendered. The id is allocated
* lazily (first time this method is invoked).
- *
+ *
* @return client id for the component
*/
public String getClientId()
{
if (clientId == null)
{
- clientId = renderSupport.allocateClientId(resources);
+ clientId = javascriptSupport.allocateClientId(resources);
element.forceAttributes("id", clientId);
}
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/BeanEditForm.properties
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/BeanEditForm.properties?rev=907055&r1=907054&r2=907055&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/BeanEditForm.properties (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/BeanEditForm.properties Fri Feb 5 18:56:40 2010
@@ -1,4 +1,4 @@
-# Copyright 2007 The Apache Software Foundation
+# Copyright 2007, 2010 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.
@@ -13,3 +13,4 @@
# limitations under the License.
submit-label=Create/Update
+cancel-label=Cancel
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/BeanEditForm.tml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/BeanEditForm.tml?rev=907055&r1=907054&r2=907055&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/BeanEditForm.tml (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/BeanEditForm.tml Fri Feb 5 18:56:40 2010
@@ -8,6 +8,9 @@
<div class="t-beaneditor-row">
<input type="submit" class="t-beaneditor-submit" value="${submitLabel}"/>
+ <t:if test="cancel">
+ <t:submit t:id="cancel" mode="cancel" value="message:cancel-label"/>
+ </t:if>
</div>
</div>
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=907055&r1=907054&r2=907055&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 Fri Feb 5 18:56:40 2010
@@ -39,6 +39,11 @@
*/
FIELD_VALIDATE_EVENT : "tapestry:fieldvalidate",
+ /** Event notification, on a form object, that is used to trigger validation on all
+ * fields within the form (observed by each field's Tapestry.FieldEventManager).
+ */
+ FORM_VALIDATE_FIELDS_EVENT : "tapestry:validatefields",
+
/** Event, fired on the document object, which identifies the current focus input element. */
FOCUS_CHANGE_EVENT : "tapestry:focuschange",
@@ -559,7 +564,7 @@
return manager;
},
-
+
/**
* Sends an Ajax request to the Form's action. This encapsulates
* a few things, such as a default onFailure handler, and working
@@ -916,6 +921,16 @@
$T(element).formFragment.setVisible(trigger.checked);
});
+ },
+
+ cancelButton : function(clientId)
+ {
+ // Set the form's skipValidation property and allow the event to continue,
+ // which will ultimately submit the form.
+
+ $(clientId).observe("click", function(event) {
+ $T(this.form).skipValidation = true;
+ });
}
};
@@ -1147,57 +1162,42 @@
this.form.onsubmit = this.handleSubmit.bindAsEventListener(this);
},
-
+
handleSubmit : function(domevent)
{
var t = $T(this.form);
t.validationError = false;
-
- var firstErrorField = null;
-
- // Locate elements that have an event manager (and therefore, validations)
- // and let those validations execute, which may result in calls to recordError().
-
-
- this.form.getElements().each(function(element)
- {
- var fem = $T(element).fieldEventManager;
-
- if (fem != undefined)
- {
- // Ask the FEM to validate input for the field, which fires
- // a number of events.
- var error = fem.validateInput();
-
- if (error && ! firstErrorField)
- {
- firstErrorField = element;
- }
- }
- });
-
- // 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). Still trying to figure out what should get focus from this
- // kind of event.
-
- this.form.fire(Tapestry.FORM_VALIDATE_EVENT, this.form);
-
- if (t.validationError)
- {
- Event.stop(domevent); // Should be domevent.stop(), but that fails under IE
-
- if (firstErrorField) firstErrorField.activate();
-
- // Because the submission failed, the last submit property is cleared,
- // since the form may be submitted for some other reason later.
-
- t.lastSubmit = null;
-
- return false;
+
+ if (!t.skipValidation) {
+
+ // Let all the fields do their validations first.
+
+ this.form.fire(Tapestry.FORM_VALIDATE_FIELDS_EVENT, this.form);
+
+ // 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). Still trying to figure out what should get focus from this
+ // kind of event.
+
+ if (!t.validationError)
+ this.form.fire(Tapestry.FORM_VALIDATE_EVENT, this.form);
+
+ if (t.validationError)
+ {
+ Event.stop(domevent); // Should be domevent.stop(), but that fails under IE
+
+ // Because the submission failed, the last submit property is cleared,
+ // since the form may be submitted for some other reason later.
+
+ t.lastSubmit = null;
+
+ return false;
+ }
+
+ t.skipValidation = false;
}
-
+
this.form.fire(Tapestry.FORM_PREPARE_FOR_SUBMIT_EVENT, this.form);
// This flag can be set to prevent the form from submitting normally.
@@ -1210,7 +1210,8 @@
Event.stop(domevent);
- // Instead ...
+ // Instead fire the event (a listener will then trigger the Ajax submission).
+ // This is really a hook for the ZoneManager.
this.form.fire(Tapestry.FORM_PROCESS_SUBMIT_EVENT);
@@ -1246,6 +1247,9 @@
this.validateInput();
}.bindAsEventListener(this));
+
+ $(this.field.form).observe(Tapestry.FORM_VALIDATE_FIELDS_EVENT,
+ this.validateInput.bindAsEventListener(this));
},
Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/app1/BeanEditorDemo.tml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/app1/BeanEditorDemo.tml?rev=907055&r1=907054&r2=907055&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/app1/BeanEditorDemo.tml (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/app1/BeanEditorDemo.tml Fri Feb 5 18:56:40 2010
@@ -1,31 +1,39 @@
<t:border xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
- <h1>${pageTitle}</h1>
+ <h1>${pageTitle}</h1>
- <form t:id="registrationData" submitlabel="Register">
-
- <t:parameter name="firstName">
- <t:label for="firstName"/>
- <input t:type="TextField" t:id="firstName" value="registrationData.firstName" size="40"/>
- (First Name is Required)
- </t:parameter>
-
- </form>
-
- <p>[<a t:type="ActionLink" t:id="clear">Clear Data</a>]
- </p>
-
- <h2>Second Form</h2>
-
- <p>Used to test tabbing
- <em>between</em>
- forms.
- </p>
-
- <p>
- <t:form t:id="search">
- <t:label for="searchTerm"/>
- <t:textfield t:id="searchTerm"/>
- <input type="submit"/>
- </t:form>
- </p>
+ <p id="message">
+ <strong>${message}</strong>
+ </p>
+
+ <form t:id="registrationData" submitlabel="Register" cancel="true">
+
+ <t:parameter name="firstName">
+ <t:label for="firstName"/>
+ <input t:type="TextField" t:id="firstName" value="registrationData.firstName" size="40"/>
+ (First Name is Required)
+ </t:parameter>
+
+ </form>
+
+ <p>
+ [
+ <a t:type="ActionLink" t:id="clear">Clear Data</a>
+ ]
+ </p>
+
+ <h2>Second Form</h2>
+
+ <p>
+ Used to test tabbing
+ <em>between</em>
+ forms.
+ </p>
+
+ <p>
+ <t:form t:id="search">
+ <t:label for="searchTerm"/>
+ <t:textfield t:id="searchTerm"/>
+ <input type="submit"/>
+ </t:form>
+ </p>
</t:border>
Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/FormTests.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/FormTests.java?rev=907055&r1=907054&r2=907055&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/FormTests.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/FormTests.java Fri Feb 5 18:56:40 2010
@@ -137,13 +137,7 @@
click(SUBMIT);
- // Looks like more weaknesses in Selenium, can only manage the first
- // match not the others.
- assertTextSeries("//div[@class='t-error-popup'][%d]/span", 1,
- "You must provide a value for First Name."
- // , "Everyone has to have a last name!",
- // "Year of Birth requires a value of at least 1900."
- );
+ assertTextPresent("You must provide a value for First Name.");
type("firstName", "Howard");
type("lastName", "Lewis Ship");
@@ -159,6 +153,21 @@
assertTextPresent("Howard", "Lewis Ship", "1966", "U.S. Citizen");
}
+
+ @Test
+ public void cancel_button()
+ {
+ clickThru("Client Validation Demo");
+
+ // Used to ensure that the <script> tag was present, but that's hard to
+ // do with script combining enabled.
+
+ clickAndWait("link=Clear Data");
+
+ clickAndWait("//input[@value='Cancel']");
+
+ assertText("message", "Form was cancelled.");
+ }
@Test
public void radio_group_validator()
Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/BeanEditorDemo.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/BeanEditorDemo.java?rev=907055&r1=907054&r2=907055&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/BeanEditorDemo.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/BeanEditorDemo.java Fri Feb 5 18:56:40 2010
@@ -4,7 +4,7 @@
// 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
+// 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,
@@ -14,8 +14,10 @@
package org.apache.tapestry5.integration.app1.pages;
+import org.apache.tapestry5.PersistenceConstants;
import org.apache.tapestry5.annotations.ApplicationState;
import org.apache.tapestry5.annotations.Component;
+import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.beaneditor.Validate;
import org.apache.tapestry5.corelib.components.BeanEditForm;
@@ -23,8 +25,11 @@
public class BeanEditorDemo
{
+ @Persist(PersistenceConstants.FLASH)
+ private String message;
+
@Component(id = "registrationData", parameters =
- {"clientValidation=clientValidation"})
+ { "clientValidation=clientValidation" })
private BeanEditForm form;
@ApplicationState
@@ -55,4 +60,19 @@
{
return "BeanEditor Component Demo";
}
+
+ public String getMessage()
+ {
+ return message;
+ }
+
+ public void setMessage(String message)
+ {
+ this.message = message;
+ }
+
+ protected void clearErrors()
+ {
+ form.clearErrors();
+ }
}
Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/ValidBeanEditorDemo.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/ValidBeanEditorDemo.java?rev=907055&r1=907054&r2=907055&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/ValidBeanEditorDemo.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/ValidBeanEditorDemo.java Fri Feb 5 18:56:40 2010
@@ -1,10 +1,10 @@
-// Copyright 2007 The Apache Software Foundation
+// Copyright 2007, 2010 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
+// 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,
@@ -29,4 +29,12 @@
return "Client Validation / BeanEditor Demo";
}
+ Object onCanceledFromRegistrationData()
+ {
+ setMessage("Form was cancelled.");
+
+ clearErrors();
+
+ return this;
+ }
}