Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Added method names & event constants names to form event table

...

Next, all the fields inside the form are activated to pull values out of the incoming request, validate them and (if valid) store the changes.

Wiki Markup
{float:right|width=25%|background=#eee}
_For Tapestry 4 Users:_ Tapestry 5 does not use the fragile "form rewind" approach from Tapestry 4. Instead, a hidden field generated during the render stores the information needed to process the form submission.
{float}
 

After the fields have done their processing, the Form emits a "validate" event. This is your chance to perform any 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 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.

...

Form Event (in order)

Phase

When emitted Typical use(and typical use)

Method Name@OnEvent Constant

prepareForRender

Render

Before rendering the form Load (e.g. load an entity from a database to be edited)

onPrepareForRender()EventConstants.PREPARE_FOR_RENDER

prepare

Render

Before rendering the form, but after prepareForRender

 

onPrepare()EventConstants.PREPARE

prepareForSubmit

prepareForSubmit

Submit

Before the submitted form is processed 

onPrepareForSubmit()EventConstants.PREPARE_FOR_SUBMIT

prepare

Submit

Before the submitted form is processed, but after prepareForSubmit 

onPrepare()EventConstants.PREPARE

validate

Submit

After fields have been populated from submitted values and validated Perform (e.g. perform cross-field validation)

onValidateEventConstants.VALIDATE

validateForm

Submit

same as validate deprecated(deprecated – do not use)

onValidateForm 

failure

Submit

After one or more validation errors have occurred 

onFailure()EventConstants.FAILURE

success

Submit

When validation has completed without any errors Save (e.g. save changes to the database)

onSuccess()EventConstants.SUCCESS

submit

Submit

submit

Submit

After all validation (success or failure) has finished 

onSubmit()EventConstants.SUBMIT

Note that the "prepare" event is emitted during both form rendering and form submission.

Handling Events

Main Article: Component Events

You handle events by providing methods in your page or component class, either following the onEventFromComponent() naming convention or using the OnEvent annotation. For example:

Code Block
languagejava
titleEvent Handler Using Naming Convention
    void onValidateFromPassword() { ...}

or the equivalent using @OnEvent:

Code Block
languagejava
titleEvent Handler Using @OnEvent Annotation
    @OnEvent(value=EventConstants.VALIDATE, component="password")
    void verifyThePassword() { ...}

Tracking Validation Errors

...