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/01/13 03:19:06 UTC
svn commit: r898624 - in /tapestry/tapestry5/trunk: src/site/apt/
src/site/apt/guide/ src/site/fml/faq/
tapestry-core/src/main/java/org/apache/tapestry5/
tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/
tapestry-core/src/test/java/o...
Author: hlship
Date: Wed Jan 13 02:19:05 2010
New Revision: 898624
URL: http://svn.apache.org/viewvc?rev=898624&view=rev
Log:
TAP5-760: The Form event "validateForm" is awkwardly named and should be replaced with the simpler name "validate"
Modified:
tapestry/tapestry5/trunk/src/site/apt/guide/validation.apt
tapestry/tapestry5/trunk/src/site/apt/index.apt
tapestry/tapestry5/trunk/src/site/fml/faq/general.fml
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/EventConstants.java
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/Form.xdoc
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/PasswordFieldDemo.java
Modified: tapestry/tapestry5/trunk/src/site/apt/guide/validation.apt
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/src/site/apt/guide/validation.apt?rev=898624&r1=898623&r2=898624&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/src/site/apt/guide/validation.apt (original)
+++ tapestry/tapestry5/trunk/src/site/apt/guide/validation.apt Wed Jan 13 02:19:05 2010
@@ -44,9 +44,12 @@
from Tapestry 4. Instead, a hidden field generated during the render stores
the information needed to process the form submission.
- After the fields have done their processing, the Form emits a "validateForm" event.
+ After the fields have done their processing, the Form emits a "validate" event.
This is a chance to perform cross-form validation that can't be described declaratively.
+ Note: For compatibility with release 5.1 and earlier, the Form component also emits
+ a "validateForm" event. See {{{https://issues.apache.org/jira/browse/TAP5-760}TAP5-760}}.
+
Next, the Form determines if there have been any validation errors. If there have been,
then the submission is considered a failure, and a "failure" event is emitted.
If there have been no validation errors, then a "success" event is emitted.
Modified: tapestry/tapestry5/trunk/src/site/apt/index.apt
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/src/site/apt/index.apt?rev=898624&r1=898623&r2=898624&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/src/site/apt/index.apt (original)
+++ tapestry/tapestry5/trunk/src/site/apt/index.apt Wed Jan 13 02:19:05 2010
@@ -93,7 +93,7 @@
@Inject
private LoginAuthenticator authenticator;
- void onValidateForm()
+ void onValidateFromForm()
{
if (! authenticator.isValidLogin(userId, password))
{
@@ -110,10 +110,10 @@
+----+
This short snippet demonstrates a bit about how Tapestry operates. Pages and services
- within the application are injected with the @Inject annotation. The method names, onValidateForm()
+ within the application are injected with the @Inject annotation. The method names, onValidateFromForm()
and onSuccess(),
- inform Tapestry about when the method is to be invoked. The two events <validateForm> and <success> occur
- when a form is submitted; "validateForm" is triggered to perform cross-field validations, and "success" is
+ 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
return value directs Tapestry on what to do next: jump to another page within the application
(here identified as the class for the page, but many other options exist). When there are exceptions,
Modified: tapestry/tapestry5/trunk/src/site/fml/faq/general.fml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/src/site/fml/faq/general.fml?rev=898624&r1=898623&r2=898624&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/src/site/fml/faq/general.fml (original)
+++ tapestry/tapestry5/trunk/src/site/fml/faq/general.fml Wed Jan 13 02:19:05 2010
@@ -178,7 +178,7 @@
the method does (i.e.,
<code>validateUserCredentials()</code>
instead of
- <code>onValidateFormFromLogin()</code>).
+ <code>onValidateFromLogin()</code>).
</p>
<p>
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=898624&r1=898623&r2=898624&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 Wed Jan 13 02:19:05 2010
@@ -1,10 +1,10 @@
-// Copyright 2008, 2009 The Apache Software Foundation
+// Copyright 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,
@@ -25,135 +25,159 @@
public static final String ACTION = "action";
/**
- * Event triggered when a page is activated (for rendering). The component event handler will be passed the context
+ * Event triggered when a page is activated (for rendering). The component event handler will be
+ * passed the context
* provided by the passivate event.
*/
public static final String ACTIVATE = "activate";
/**
- * Event triggered when a link for a page is generated. The event handler for the page may provide an object, or an
- * array of objects, as the context for the page. These values will become part of the page's context, and will be
+ * Event triggered when a link for a page is generated. The event handler for the page may
+ * provide an object, or an
+ * array of objects, as the context for the page. These values will become part of the page's
+ * context, and will be
* provided back when the page is activated.
*/
public static final String PASSIVATE = "passivate";
/**
* Invoked before {@link #PREPARE} when rendering out the form.
- *
+ *
* @see org.apache.tapestry5.corelib.components.Form
*/
public static final String PREPARE_FOR_RENDER = "prepareForRender";
/**
* Invoked before {@link #PREPARE} when the form is submitted.
- *
+ *
* @see org.apache.tapestry5.corelib.components.Form
*/
public static final String PREPARE_FOR_SUBMIT = "prepareForSubmit";
/**
- * Invoked to let the containing component(s) prepare for the form rendering or the form submission.
- *
+ * Invoked to let the containing component(s) prepare for the form rendering or the form
+ * submission.
+ *
* @see org.apache.tapestry5.corelib.components.Form
*/
public static final String PREPARE = "prepare";
/**
- * Event type for a notification after the form has submitted. This event notification occurs on any form submit,
+ * Event type for a notification after the form has submitted. This event notification occurs on
+ * any form submit,
* without respect to "success" or "failure".
- *
+ *
* @see org.apache.tapestry5.corelib.components.Form
*/
public static final String SUBMIT = "submit";
/**
- * 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.
- *
+ * 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.
+ *
* @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.
*/
public static final String VALIDATE_FORM = "validateForm";
/**
- * Event type for a notification after the form has submitted, when there are no errors in the validation tracker.
+ * 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.
- *
+ *
* @see org.apache.tapestry5.corelib.components.Form
*/
public static final String SUCCESS = "success";
/**
- * Event type for a notification after the form has been submitted, when there are errors in the validation tracker.
+ * Event type for a notification after the form has been submitted, when there are errors in the
+ * validation tracker.
* This occurs before the {@link #SUBMIT} event.
*/
public static final String FAILURE = "failure";
/**
- * Event type triggered by the {@link org.apache.tapestry5.corelib.components.Submit} component when it is the cause
+ * Event type triggered by the {@link org.apache.tapestry5.corelib.components.Submit} component
+ * when it is the cause
* of the form submission.
*/
public static final String SELECTED = "selected";
/**
- * Event triggered by some form-related cmponents to parse a value provided by the client. This takes the place of a
- * {@link org.apache.tapestry5.Translator}.
+ * Event triggered by some form-related cmponents 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";
/**
- * Event triggered by some form-related components to convert a server-side value to a client-side string, as an
+ * Event triggered by some form-related components to convert a server-side value to a
+ * client-side string, as an
* alternative to a {@link org.apache.tapestry5.Translator}.
*/
public static final String TO_CLIENT = "toClient";
/**
- * Event triggered by form-related components to validate user input.
+ * Event triggered by form-related components to validate user input. In addition, the Form component
+ * fires a validate event just before it fires {@link #SUCCESS} or {@link #FAILURE} as a chance
+ * to perform cross-form validations.
*/
public static final String VALIDATE = "validate";
/**
- * Event triggered by {@link org.apache.tapestry5.corelib.components.AjaxFormLoop} to inform the container about the
- * row removed on the client side. The event context is the object that was removed.
+ * Event triggered by {@link org.apache.tapestry5.corelib.components.AjaxFormLoop} to inform the
+ * container about the
+ * row removed on the client side. The event context is the object that was removed.
*/
public static final String REMOVE_ROW = "removeRow";
/**
- * Event triggered by {@link org.apache.tapestry5.corelib.components.AjaxFormLoop} to inform the container that a
- * new row has been requested. The return value from the event handler must be the newly created object, which must
+ * Event triggered by {@link org.apache.tapestry5.corelib.components.AjaxFormLoop} to inform the
+ * container that a
+ * new row has been requested. The return value from the event handler must be the newly created
+ * object, which must
* also be visible in the {@link org.apache.tapestry5.PrimaryKeyEncoder encoder parameter}.
*/
public static final String ADD_ROW = "addRow";
/**
- * Event triggered by the {@link org.apache.tapestry5.corelib.components.Loop} component to inform its container of
- * all the values that were supplied from the client during a form submission. The event handler method should have
+ * Event triggered by the {@link org.apache.tapestry5.corelib.components.Loop} component to
+ * inform its container of
+ * all the values that were supplied from the client during a form submission. The event handler
+ * method should have
* a single parameter, of type Object[] or type List, to receive the values.
- *
+ *
* @since 5.1.0.0
*/
public static final String SYNCHRONIZE_VALUES = "synchronizeValues";
/**
- * 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
+ * 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.
- *
+ *
* @since 5.1.0.1
*/
public static final String PROGRESSIVE_DISPLAY = "progressiveDisplay";
/**
- * Event triggered by an {@link org.apache.tapestry5.corelib.mixins.Autocomplete} mixin to request completions of
+ * Event triggered by an {@link org.apache.tapestry5.corelib.mixins.Autocomplete} mixin to
+ * request completions of
* the current input. The context is the partial string provided by the client.
- *
+ *
* @SINCE 5.1.0.4
*/
public static final String PROVIDE_COMPLETIONS = "providecompletions";
-
+
/**
- * Event triggered by {@link org.apache.tapestry5.corelib.components.Select} component to inform its
+ * Event triggered by {@link org.apache.tapestry5.corelib.components.Select} component to inform
+ * its
* container that Select's value has changed.
- *
+ *
* @since 5.2.0.0
*/
public static final String VALUE_CHANGED = "valuechanged";
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=898624&r1=898623&r2=898624&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 Wed Jan 13 02:19:05 2010
@@ -47,19 +47,17 @@
* <p/>
* A Form emits many notification events. When it renders, it fires a
* {@link org.apache.tapestry5.EventConstants#PREPARE_FOR_RENDER} notification, followed by a
- * {@link org.apache.tapestry5.EventConstants#PREPARE} notification.
+ * {@link EventConstants#PREPARE} notification.
* <p/>
* When the form is submitted, the component emits several notifications: first a
- * {@link org.apache.tapestry5.EventConstants#PREPARE_FOR_SUBMIT}, then a
- * {@link org.apache.tapestry5.EventConstants#PREPARE}: these allow the page to update its state as
- * necessary to prepare for the form submission, then (after components enclosed by the form have
- * operated), a {@link org.apache.tapestry5.EventConstants#VALIDATE_FORM} event is emitted, to allow
- * for cross-form validation. After that, either a
- * {@link org.apache.tapestry5.EventConstants#SUCCESS} OR
- * {@link org.apache.tapestry5.EventConstants#FAILURE} event (depending on whether the
- * {@link ValidationTracker} has recorded any errors). Lastly, a
- * {@link org.apache.tapestry5.EventConstants#SUBMIT} event, for any listeners that care only about
- * form submission, regardless of success or failure.
+ * {@link EventConstants#PREPARE_FOR_SUBMIT}, then a {@link EventConstants#PREPARE}: these allow the
+ * page to update its state as necessary to prepare for the form submission, then (after components
+ * enclosed by the form have operated), a {@link EventConstants#VALIDATE} event is emitted (followed
+ * by a {@link EventConstants#VALIDATE_FORM} event, for backwards compatibility), to allow for
+ * cross-form validation. After that, either a {@link EventConstants#SUCCESS} OR
+ * {@link EventConstants#FAILURE} event (depending on whether the {@link ValidationTracker} has
+ * recorded any errors). Lastly, a {@link EventConstants#SUBMIT} event, for any listeners that care
+ * only about form submission, regardless of success or failure.
* <p/>
* For all of these notifications, the event context is derived from the <strong>context</strong>
* parameter. This context is encoded into the form's action URI (the parameter is not read when the
@@ -67,42 +65,42 @@
*/
@Events(
{ EventConstants.PREPARE_FOR_RENDER, EventConstants.PREPARE, EventConstants.PREPARE_FOR_SUBMIT,
- EventConstants.VALIDATE_FORM, EventConstants.SUBMIT, EventConstants.FAILURE,
- EventConstants.SUCCESS })
+ EventConstants.VALIDATE, EventConstants.VALIDATE_FORM, EventConstants.SUBMIT,
+ EventConstants.FAILURE, EventConstants.SUCCESS })
public class Form implements ClientElement, FormValidationControl
{
/**
- * @deprecated Use constant from {@link org.apache.tapestry5.EventConstants} instead.
+ * @deprecated Use constant from {@link EventConstants} instead.
*/
public static final String PREPARE_FOR_RENDER = EventConstants.PREPARE_FOR_RENDER;
/**
- * @deprecated Use constant from {@link org.apache.tapestry5.EventConstants} instead.
+ * @deprecated Use constant from {@link EventConstants} instead.
*/
public static final String PREPARE_FOR_SUBMIT = EventConstants.PREPARE_FOR_SUBMIT;
/**
- * @deprecated Use constant from {@link org.apache.tapestry5.EventConstants} instead.
+ * @deprecated Use constant from {@link EventConstants} instead.
*/
public static final String PREPARE = EventConstants.PREPARE;
/**
- * @deprecated Use constant from {@link org.apache.tapestry5.EventConstants} instead.
+ * @deprecated Use constant from {@link EventConstants} instead.
*/
public static final String SUBMIT = EventConstants.SUBMIT;
/**
- * @deprecated Use constant from {@link org.apache.tapestry5.EventConstants} instead.
+ * @deprecated Use constant from {@link EventConstants} instead.
*/
public static final String VALIDATE_FORM = EventConstants.VALIDATE_FORM;
/**
- * @deprecated Use constant from {@link org.apache.tapestry5.EventConstants} instead.
+ * @deprecated Use constant from {@link EventConstants} instead.
*/
public static final String SUCCESS = EventConstants.SUCCESS;
/**
- * @deprecated Use constant from {@link org.apache.tapestry5.EventConstants} instead.
+ * @deprecated Use constant from {@link EventConstants} instead.
*/
public static final String FAILURE = EventConstants.FAILURE;
@@ -172,7 +170,7 @@
/**
* Prefix value used when searching for validation messages and constraints.
* The default is the Form component's
- * id. This is overriden by {@link org.apache.tapestry5.corelib.components.BeanEditForm}.
+ * id. This is overridden by {@link org.apache.tapestry5.corelib.components.BeanEditForm}.
*
* @see org.apache.tapestry5.services.FormSupport#getFormValidationId()
*/
@@ -230,6 +228,7 @@
/**
* Set up via the traditional or Ajax component event request handler
*/
+ @SuppressWarnings("unchecked")
@Environmental
private ComponentEventResultProcessor componentEventResultProcessor;
@@ -531,11 +530,22 @@
}
private void fireValidateFormEvent(EventContext context,
+ ComponentResultProcessorWrapper callback) throws IOException
+ {
+ fireValidateEvent(EventConstants.VALIDATE, context, callback);
+
+ if (callback.isAborted())
+ return;
+
+ fireValidateEvent(EventConstants.VALIDATE_FORM, context, callback);
+ }
+
+ private void fireValidateEvent(String eventName, EventContext context,
ComponentResultProcessorWrapper callback)
{
try
{
- resources.triggerContextEvent(EventConstants.VALIDATE_FORM, context, callback);
+ resources.triggerContextEvent(eventName, context, callback);
}
catch (RuntimeException ex)
{
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Form.xdoc
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Form.xdoc?rev=898624&r1=898623&r2=898624&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Form.xdoc (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Form.xdoc Wed Jan 13 02:19:05 2010
@@ -132,6 +132,7 @@
<ul>
<li>prepareForSubmit</li>
<li>prepare</li>
+ <li>validate</li>
<li>validateForm</li>
<li>failure
<em>or</em>
@@ -141,8 +142,10 @@
</ul>
<p>
- The validateForm event is to allow the page to
- perform cross-field validation. The failure or success
+ The validate event is to allow the page to
+ perform cross-field validation. The validateForm event is a deprecated name for the
+ validate event (it currently exists only for backwards compatibility).
+ The failure or success
event is fired based on whether there are or are not any
validation errors.
</p>
Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/PasswordFieldDemo.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/PasswordFieldDemo.java?rev=898624&r1=898623&r2=898624&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/PasswordFieldDemo.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/PasswordFieldDemo.java Wed Jan 13 02:19:05 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,
@@ -15,6 +15,7 @@
package org.apache.tapestry5.integration.app1.pages;
import org.apache.tapestry5.annotations.Component;
+import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.annotations.Retain;
import org.apache.tapestry5.corelib.components.Form;
import org.apache.tapestry5.corelib.components.PasswordField;
@@ -23,11 +24,11 @@
public class PasswordFieldDemo
{
- @Retain
+ @Persist
private String userName;
// Normally not retained, just want to prove that the output value is always the blank string.
- @Retain
+ @Persist
private String password;
@Inject