[CONF] Apache Tapestry Forms and Validation

2013-10-14 Thread Bob Harner (Confluence)







Forms and Validation
Page edited by Bob Harner


Comment:
Corrected error in onValidateXXX method example


 Changes (1)
 




...
 * Do the cross-field validation  */ 
void onValidateFromLoginForm() 
{ if (!authenticator.isValid(userName, password)) 
...


Full Content


Related Articles


 Page:
 Forms and Validation





 Page:
 Forms and Form Components FAQ





 Page:
 Bean Validation






The life's blood of any application is form input; this is the most effective way to gather significant information from the user. Whether it's a search form, a login screen or a multi-page registration wizard, forms are how the user really expresses themselves to the application.

Tapestry excels at creating forms and validating input. Input validation is declarative, meaning you simply tell Tapestry what validations to apply to a given field, and it takes care of it on the server and (once implemented) on the client as well.

Finally, Tapestry is able to not only present the errors back to the user, but to decorate the fields and the labels for the fields, marking them as containing errors (primarily, using CSS effects).

Contents



The Form Component

Form Events
Tracking Validation Errors
Storing Data Between Requests
Configuring Fields and Labels
Errors and Decorations

Form Validation

Available Validators
Centralizing Validation with @Validate
Customizing Validation Messages

Customizing Validation Messages for BeanEditForm

Configuring Validator Contraints in the Message Catalog
Validation Macros
Overriding the Translator with Events



The Form Component

The core of Tapestry's form support is the Form component. The Form component encloses (wraps around) all the other field components such as TextField, TextArea, Checkbox, etc.

Form Events

The Form component emits a number of component events. You'll need to provide event handler methods for some of these.

When rendering, the Form component emits two notifications: first, "prepareForRender", then "prepare". These allow the Form's container to setup any fields or properties that will be referenced in the form. For example, this is a good place to create a temporary entity object to be rendered, or to load an entity from a database to be edited.

When user submits the form on the client, a series of steps occur on the server.

First, the Form emits a "prepareForSubmit" notification, then a "prepare" notification. These allow the container to ensure that objects are set up and ready to receive information from the form submission.

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.

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.

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 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.

Finally, the Form emits a "submit" event, for logic that doesn't care about success or failure.




 Form Event (in order) 
 Phase 
 When emitted 
 Typical use 


 prepareForRender 
 Render 
 Before rendering the form 
 Load an entity from a database to be edited 


 prepare 
 Render 
 Before rendering the form, but after prepareForRender 



 prepareForSubmit 
 Submit 
 Before the submitted form is processed 



 prepare 
 Submit 
 Before the submitted form is processed, but after prepareForSubmit 



 validate 
 Submit 
 After fields have been populated from submitted values and validated 
 Perform cross-field validation 


 validateForm 
 Submit 
 same as validate 
 deprecated 


 failure 
 Submit 
 After one or more validation 

[CONF] Apache Tapestry Forms and Validation

2013-02-10 Thread confluence







Forms and Validation
Page edited by Bob Harner


Comment:
Fixed mixed up table of available validators


 Changes (4)
 




...
 || Validator || Constraint Type || Description || Example || 
| email | --  | Ensures that the given input is looks like a valid e-mail address | {{t:textfield value=email validate=email /}} | 
| max | long | Enforces a maximum integer value | {{t:textfield value=age validate=max=120,min=0 /}} | | maxLength | int | Makes sure that a string value has a maximum length | {{t:textfield value=zip validate=maxlength=7 /}} | | min | long | Enforces a minimum integer value | {{t:textfield value=age validate=max=120,min=0 /}} | 
| minLength | int | Makes sure that a string value has a minimum length | {{t:textfield value=somefield validate=minlength=1 /}} | 
| minLength none | int -- | Does nothing (used to override a @Validate annotation) | {{t:textfield value=somefield validate=none /}} | 
| none | -- | Makes sure that a string value has a minimum length | {{t:textfield value=somefield validate=minlength=1 /}} | 
| regexp | pattern | Makes sure that a string value conforms to a given pattern | {{t:textfield value=letterfield validate=regexp=\^}}{{\[A-Za-z\]\+$ /}} | | required | --  | Makes sure that a string value is not null and not the empty string | {{t:textfield value=name validate=required /}} | 
...


Full Content


Related Articles


 Page:
 Forms and Validation





 Page:
 Forms and Form Components FAQ





 Page:
 Bean Validation






The life's blood of any application is form input; this is the most effective way to gather significant information from the user. Whether it's a search form, a login screen or a multi-page registration wizard, forms are how the user really expresses themselves to the application.

Tapestry excels at creating forms and validating input. Input validation is declarative, meaning you simply tell Tapestry what validations to apply to a given field, and it takes care of it on the server and (once implemented) on the client as well.

Finally, Tapestry is able to not only present the errors back to the user, but to decorate the fields and the labels for the fields, marking them as containing errors (primarily, using CSS effects).

Contents



The Form Component

Form Events
Tracking Validation Errors
Storing Data Between Requests
Configuring Fields and Labels
Errors and Decorations

Form Validation

Available Validators
Centralizing Validation with @Validate
Customizing Validation Messages

Customizing Validation Messages for BeanEditForm

Configuring Validator Contraints in the Message Catalog
Validation Macros
Overriding the Translator with Events



The Form Component

The core of Tapestry's form support is the Form component. The Form component encloses (wraps around) all the other field components such as TextField, TextArea, Checkbox, etc.

Form Events

The Form component emits a number of component events. You'll need to provide event handler methods for some of these.

When rendering, the Form component emits two notifications: first, "prepareForRender", then "prepare". These allow the Form's container to setup any fields or properties that will be referenced in the form. For example, this is a good place to create a temporary entity object to be rendered, or to load an entity from a database to be edited.

When user submits the form on the client, a series of steps occur on the server.

First, the Form emits a "prepareForSubmit" notification, then a "prepare" notification. These allow the container to ensure that objects are set up and ready to receive information from the form submission.

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.

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.

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 

[CONF] Apache Tapestry Forms and Validation

2012-04-28 Thread confluence







Forms and Validation
Page edited by Bob Harner


Comment:
Address event handler issue raised in the reopened TAP5-812


 Changes (8)
 




...
private Form form;  
String onSuccess() 
/**  * Do the cross-field validation  */ void onValidateFromLoginForm() 
{ if (!authenticator.isValid(userName, password)) { 
// record an error, and thereby prevent Tapestry from emitting a success event 
form.recordError(passwordField, Invalid user name or password.); 
return null; 
} 
} 
 
/**  * Validation passed, so well go to the PostLogin page  */ Object onSuccess() { 
return PostLogin; } 
...
{float:right|width=40%} {info} 
Note that the onValidateFromLoginForm() and onSuccess() method is are not public; event handler methods can have any visibility, even private. Package private (that is, no modifier) is the typical use, as it allows the component to be tested, from a test case class in the same package. 
{info} {float} 
...
h1Please Login/h1  
form t:type=form t:id=form t:id=loginForm 
 t:errors/ 
...


Full Content


Related Articles


 Page:
 Forms and Validation





 Page:
 Forms and Form Components FAQ





 Page:
 Bean Validation






The life's blood of any application is form input; this is the most effective way to gather significant information from the user. Whether it's a search form, a login screen or a multi-page registration wizard, forms are how the user really expresses themselves to the application.

Tapestry excels at creating forms and validating input. Input validation is declarative, meaning you simply tell Tapestry what validations to apply to a given field, and it takes care of it on the server and (once implemented) on the client as well.

Finally, Tapestry is able to not only present the errors back to the user, but to decorate the fields and the labels for the fields, marking them as containing errors (primarily, using CSS effects).

Form component

The core of Tapestry's form support is the Form component. The Form component encloses (wraps around) all the other field components such as TextField, TextArea, Checkbox, etc.

The Form component generates a number of component events that you may provide event handler methods for.

When rendering, the Form component emits two notifications: first, "prepareForRender", then "prepare". These allow the Form's container to setup any fields or properties that will be referenced in the form. For example, this is a good place to create a temporary entity object to be rendered, or to load an entity from a database to be edited.

When user submits the form on the client, a series of steps occur on the server.

First, the Form emits a "prepareForSubmit" notification, then a "prepare" notification. These allow the container to ensure that objects are set up and ready to receive information from the form submission.

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.

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.

After the fields have done their processing, the Form emits a "validateForm" event. This is a chance to perform cross-form validation that can't be described declaratively.

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.

Last, the Form emits a "submit" event (for logic that doesn't care about success or failure).

Tracking Validation Errors

Associated with the Form is a ValidationTracker that tracks all the provided user input and validation errors for every field in the form. The tracker can be provided to the Form 

[CONF] Apache Tapestry Forms and Validation

2012-03-22 Thread confluence







Forms and Validation
Page edited by Bob Harner


Comment:
Some wordsmithing and a little more about serialization


 Changes (13)
 




...
h1. Storing Data Between Requests  
{float:right|background="">width=40%} 
{info:title=New in Tapestry 5.4} Starting in Tapestry 5.4, the default behavior for server-side validation failures is to re-render the page within the same request (rather than emitting a redirect). This removes the need to use a session-persistent field to store the validation tracker when validation failures occur. 
{since:5.4} {info} 
Note: Starting in Tapestry 5.4, the default behavior for server-side validation failures is to re-render the page within the same request (rather than emitting a redirect). This removes the need to use a persistent field to store the tracker. {since} 
{float}  
As with other action requests, the result of a form submission is to send a redirect to the client which re-renders the page. The ValidationTracker must be stored [persistently|Persistent Page Data] between requests, or all the validation information will be lost (the default ValidationTracker provided by the Form is persistent). 
As with other action requests, the result of a form submission is to send a redirect to the client, which results in a second request (to re-render the page). The ValidationTracker must be [persisted|Persistent Page Data] (generally in the HttpSession) across these two requests in order to prevent the loss of validation information. Fortunately, the default ValidationTracker provided by the Form component is persistent, so you dont normally have to worry about it. 
 
Likewise, the individual fields updated by the components should also be persistent. 
However, for the same reason, the individual fields updated by the components should also be persisted across requests, and this is something you *do* need to do yourself -- generally with the @Persist annotation. 
 For example, a Login page, which collects a user name and a password, might look like: 
...
{code}  
Because of the the fact that a form submission is _two_ requests (the submission itself, then a re-render of the page), it is necessary to make the value stored in the userName field persist between the two requests. This would be necessary for the password field as well, except that the [PasswordField|http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/corelib/components/PasswordField.html] component never renders a value. 
{float:right|width=40%} 
  {info} 
Note that the onSuccess() method is not public; event handler methods can have any visibility, even private. Package private (that is, no modifier) is the typical use, as it allows the component to be tested, from a test case class in the same package. 
{info} {float} 
 
Because a form submission is really _two_ requests: the submission itself (which results in a redirect response), then a second request for the page (which results in a re-rendering of the page), it is necessary to persist the userName field between the two requests, by using the @Persist annotation. This would be necessary for the password field as well, except that the [PasswordField|http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/corelib/components/PasswordField.html] component never renders a value.  {tip} To avoid data loss, fields whose values are stored in the HttpSession (such as userName, above) must be serializable, particularly if you want to be able to cluster your application or preserve sessions across server restarts. {tip}  
The Form only emits a success event if the there are no prior validation errors. This means it is not necessary to write {{if (form.getHasErrors()) return;}} as the first line of the method.  
...


Full Content


Related Articles


 Page:
 Forms and Validation





 Page:
 Forms and Form Components FAQ





 Page:
 Bean Validation






The life's blood of any application is form input; this is the most effective way to gather significant information from the user. Whether 

[CONF] Apache Tapestry Forms and Validation

2012-03-16 Thread confluence







Forms and Validation
Page edited by Bob Harner


Comment:
Added note about Tap 5.4 not redirecting after form validation failures


 Changes (1)
 




...
h1. Storing Data Between Requests  
{float:right|background="" {since:5.4} Note: Starting in Tapestry 5.4, the default behavior for server-side validation failures is to re-render the page within the same request (rather than emitting a redirect). This removes the need to use a persistent field to store the tracker. {since} {float}  
As with other action requests, the result of a form submission is to send a redirect to the client which re-renders the page. The ValidationTracker must be stored [persistently|Persistent Page Data] between requests, or all the validation information will be lost (the default ValidationTracker provided by the Form is persistent).  
...


Full Content


Related Articles


 Page:
 Forms and Validation





 Page:
 Forms and Form Components FAQ





 Page:
 Bean Validation






The life's blood of any application is form input; this is the most effective way to gather significant information from the user. Whether it's a search form, a login screen or a multi-page registration wizard, forms are how the user really expresses themselves to the application.

Tapestry excels at creating forms and validating input. Input validation is declarative, meaning you simply tell Tapestry what validations to apply to a given field, and it takes care of it on the server and (once implemented) on the client as well.

Finally, Tapestry is able to not only present the errors back to the user, but to decorate the fields and the labels for the fields, marking them as containing errors (primarily, using CSS effects).

Form component

The core of Tapestry's form support is the Form component. The Form component encloses (wraps around) all the other field components such as TextField, TextArea, Checkbox, etc.

The Form component generates a number of component events that you may provide event handler methods for.

When rendering, the Form component emits two notifications: first, "prepareForRender", then "prepare". These allow the Form's container to setup any fields or properties that will be referenced in the form. For example, this is a good place to create a temporary entity object to be rendered, or to load an entity from a database to be edited.

When user submits the form on the client, a series of steps occur on the server.

First, the Form emits a "prepareForSubmit" notification, then a "prepare" notification. These allow the container to ensure that objects are set up and ready to receive information from the form submission.

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.

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.

After the fields have done their processing, the Form emits a "validateForm" event. This is a chance to perform cross-form validation that can't be described declaratively.

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.

Last, the Form emits a "submit" event (for logic that doesn't care about success or failure).

Tracking Validation Errors

Associated with the Form is a ValidationTracker that tracks all the provided user input and validation errors for every field in the form. The tracker can be provided to the Form via the Form's tracker parameter, but this is rarely necessary.

The Form includes methods isValid() and getHasErrors(), which are used to see if the Form's validation tracker contains any errors.

In your own logic, it is possible to record your own errors. Form includes two different versions of method recordError(), one of which specifies a Field (an interface implemented by all form element components), and one of which is for "global" errors, unassociated with any particular field.

Storing Data Between Requests




[CONF] Apache Tapestry Forms and Validation

2011-10-19 Thread confluence







Forms and Validation
Page edited by Howard M. Lewis Ship


Comment:
Use JavaDoc not 5.2 component reference


 Changes (4)
 




...
h1. Form component  
The core of Tapestrys form support is the [Form|http://tapestry.apache.org/current/tapestry-core/ref/org/apache/tapestry5/corelib/components/Form.html] [Form|http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/corelib/components/Form.html] component. The Form component encloses (wraps around) all the other _field components_ such as [TextField|http://tapestry.apache.org/current/tapestry-core/ref/org/apache/tapestry5/corelib/components/TextField.html], [TextArea|http://tapestry.apache.org/current/tapestry-core/ref/org/apache/tapestry5/corelib/components/TextArea.html], [Checkbox|http://tapestry.apache.org/current/tapestry-core/ref/org/apache/tapestry5/corelib/components/Checkbox.html], [TextField|http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/corelib/components/TextField.html], [TextArea|http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/corelib/components/TextArea.html], [Checkbox|http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/corelib/components/Checkbox.html], etc. 
 The Form component generates a number of [component events|Component Events] that you may provide event handler methods for. 
...
{code}  
Because of the the fact that a form submission is _two_ requests (the submission itself, then a re-render of the page), it is necessary to make the value stored in the userName field persist between the two requests. This would be necessary for the password field as well, except that the [PasswordField|http://tapestry.apache.org/current/tapestry-core/ref/org/apache/tapestry5/corelib/components/PasswordField.html] [PasswordField|http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/corelib/components/PasswordField.html] component never renders a value. 
 Note that the onSuccess() method is not public; event handler methods can have any visibility, even private. Package private (that is, no modifier) is the typical use, as it allows the component to be tested, from a test case class in the same package. 
...
The Tapestry Form component is responsible for creating the necessary URL for the form submission (this is Tapestrys responsibility, not yours).  
The [Errors|http://tapestry.apache.org/current/tapestry-core/ref/org/apache/tapestry5/corelib/components/Errors.html] [Errors|http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/corelib/components/Errors.html] component must be placed inside a Form, it outputs all of the errors for all the fields within the Form as a single list. It uses some simple styling to make the result more presentable. 
 
Each field component, such as the TextField, is paired with a [Label|http://tapestry.apache.org/current/tapestry-core/ref/org/apache/tapestry5/corelib/components/Label.html] [Label|http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/corelib/components/Label.html] component. The Label will render out a label element connected to the field. This is very important for usability, especially for users with visual disabilities. It also means you can click on the label text to move the cursor to the corresponding field. 
 The {{for}} parameter of the Label is the id of a component. 
...


Full Content


Related Articles


 Page:
 Forms and Validation





 Page:
 Forms and Form Components FAQ





 Page:
 Bean Validation






The life's blood of any application is form input; this is the most effective way to gather significant information from the user. Whether it's a search form, a login screen or a multi-page registration wizard, forms are how the user really expresses themselves to the application.

Tapestry excels at creating forms and validating input. Input validation is declarative, meaning you simply tell Tapestry what validations to apply to a given field, and it takes care of it on the server and (once implemented) on the client as well.

Finally, Tapestry is able to not only present the errors back to the user, but to decorate the fields and the labels for the 

[CONF] Apache Tapestry Forms and Validation

2011-07-21 Thread confluence







Forms and Validation
Page edited by DEMEY Emmanuel


 Changes (1)
 




...
h1Please Login/h1  
form t:type=form t:id=form 
 t:errors/ 
...


Full Content


Related Articles


 Page:
 Forms and Validation





 Page:
 Bean Validation





 Page:
 Forms and Form Components FAQ






The life's blood of any application is form input; this is the most effective way to gather significant information from the user. Whether it's a search form, a login screen or a multi-page registration wizard, forms are how the user really expresses themselves to the application.

Tapestry excels at creating forms and validating input. Input validation is declarative, meaning you simply tell Tapestry what validations to apply to a given field, and it takes care of it on the server and (once implemented) on the client as well.

Finally, Tapestry is able to not only present the errors back to the user, but to decorate the fields and the labels for the fields, marking them as containing errors (primarily, using CSS effects).

Form component

The core of Tapestry's form support is the Form component. The Form component encloses (wraps around) all the other field components such as TextField, TextArea, Checkbox, etc.

The Form component generates a number of component events that you may provide event handler methods for.

When rendering, the Form component emits two notifications: first, "prepareForRender", then "prepare". These allow the Form's container to setup any fields or properties that will be referenced in the form. For example, this is a good place to create a temporary entity object to be rendered, or to load an entity from a database to be edited.

When user submits the form on the client, a series of steps occur on the server.

First, the Form emits a "prepareForSubmit" notification, then a "prepare" notification. These allow the container to ensure that objects are set up and ready to receive information from the form submission.

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.

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.

After the fields have done their processing, the Form emits a "validateForm" event. This is a chance to perform cross-form validation that can't be described declaratively.

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.

Last, the Form emits a "submit" event (for logic that doesn't care about success or failure).

Tracking Validation Errors

Associated with the Form is an ValidationTracker that tracks all the provided user input and validation errors for every field in the form. The tracker can be provided to the Form via the Form's tracker parameter, but this is rarely necessary.

The Form includes methods isValid() and getHasErrors(), which are used to see if the Form's validation tracker contains any errors.

In your own logic, it is possible to record your own errors. Form includes two different versions of method recordError(), one of which specifies a Field (an interface implemented by all form element components), and one of which is for "global" errors, unassociated with any particular field.

Storing Data Between Requests

As with other action requests, the result of a form submission is to send a redirect to the client which re-renders the page. The ValidationTracker must be stored persistently between requests, or all the validation information will be lost (the default ValidationTracker provided by the Form is persistent).

Likewise, the individual fields updated by the components should also be persistent.

For example, a Login page, which collects a user name and a password, might look like:



public class Login
{
@Persist
private String userName;

private String password;

@Inject
private UserAuthenticator authenticator;

@Component(id = "password")
private PasswordField 

[CONF] Apache Tapestry Forms and Validation

2011-07-21 Thread confluence







Forms and Validation
Page edited by DEMEY Emmanuel


 Changes (10)
 




...
The template for a page contains a minimal amount of Tapestry instrumentation:  
{code:java} {code:html} 
html xmlns:t=http://tapestry.apache.org/schema/tapestry_5_1_0.xsd head 
...
The message can be customized by adding an entry to the pages [message catalog|Localization] (or the containing components message catalog). As with any localized property, this can also go into the applications message catalog.  
The first key checked is _formId_\-_fieldId_\-_validatorName_\-message. 
 * formId: the local component id of the Form component * fieldId: the local component id of the field (TextField, etc.) * validatorName: the name of the validator, i.e., required or minlength 
If there is not message for that key, a second check is made, for _fieldId_\-_validatorName_\-message. 
 If that does not match a message, then the built-in default validation message is used. 
...
This is useful when the validation constraint is awkward to enter inline, such as a regular _expression_ for use with the regexp validator.  
The key here is similar to customizing the validation message: _formId_\-_fieldId_\-_validatorName_ or just _fieldId_\-_validatorName_. 
 For example, your template may have the following:  
{code:java} {code:html} 
  t:textfield t:id=ssn validate=required,regexp/ {code} 
...
 | Validator | Constraint Type | Description | Example | 
| email | -   | Ensures that the given input is a valid e-mail address | {{t:textfield value=email validate=email /}} | 
| max | long | Enforces a maximum integer value | {{t:textfield value=age validate=max=120,min=0 /}} | | maxLength | int | Makes sure that a string value has a maximum length | {{t:textfield value=zip validate=maxlength=7 /}} | | min | long | Enforces a minimum integer value | {{t:textfield value=age validate=max=120,min=0 /}} | | minLength | int | Makes sure that a string value has a minimum length | {{t:textfield value=somefield validate=minlength=1 /}} | 
| regexp | pattern | Makes sure that a string value conforms to a given pattern | {{t:textfield value=otherfield validate=regexp=^[a-z]+$ validate=regexp=\^}}{{[a-z|a-z]}}{{\+$ /}} | 
| required | -   | Makes sure that a string value is not null and not the empty string | {{t:textfield value=name validate=required /}} | 
 
h1. Validation Macros  Since Tapestry 5.2, we can create validation macros, wich will contain a list of validators. This mechanism is very useful for combining your validators. We just have to contribute to the ValidatorMacro Service in your AppModule, by adding a new entry to the configuration object. The first parameter is the name of your macro, the second is a comma-separated list of validators.  {code:java} @Contribute(ValidatorMacro.class) public static void combinePasswordValidators(MappedConfigurationString, String configuration) {   configuration.add(password,required,minlength=5,maxlength=15,); } {code}  Then, we can use this new macro in our Template or Java Class.  {code:html} input t:type=textField t:id=password t:validate=password / {code}  {code:java} @Validate(password) private String password; {code}  
h1. Overriding the Translator with Events  
...
{code}  
The event handler method has precedence over the translator. Here it checks for the empty string (and note that the input may be null\!) and evaluates that as zero. 
 Again, returning null lets the normal translator do its work. 
...


Full Content


Related Articles


 Page:
 Forms and Validation





 Page:
 Bean Validation





 Page:
 Forms and Form Components FAQ






The life's blood of any application is form input; this is the most effective way to gather significant information from the user. Whether it's a search form, a login screen or a multi-page registration wizard, forms are how the user really expresses themselves to the application.

Tapestry excels at creating forms and validating input. Input validation is 

[CONF] Apache Tapestry Forms and Validation

2011-07-21 Thread confluence







Forms and Validation
Page
comment added by  DEMEY Emmanuel



   Hi everybody

I am working on the Validation part of this documentation page. But it become quite big. I would like to split it into 2 pages : 

	Form
	Validation



Can I do this my myself ?

Thanks

Emmanuel  




   
Change Notification Preferences
   
   View Online
   









[CONF] Apache Tapestry Forms and Validation

2011-06-04 Thread confluence







Forms and Validation
Page edited by Bob Harner


Comment:
Renamed (has to have the word Form in it, since it is the main "forms" page!)


 Changes (0)
 




...


Full Content


Related Articles


 Page:
 Bean Validation





 Page:
 Forms and Validation






Form Input and Validation

The life's blood of any application is form input; this is the most effective way to gather significant information from the user. Whether it's a search form, a login screen or a multi-page registration wizard, forms are how the user really expresses themselves to the application.

Tapestry excels at creating forms and validating input. Input validation is declarative, meaning you simply tell Tapestry what validations to apply to a given field, and it takes care of it on the server and (once implemented) on the client as well.

Finally, Tapestry is able to not only present the errors back to the user, but to decorate the fields and the labels for the fields, marking them as containing errors (primarily, using CSS effects).

Form component

The core of Tapestry's form support is the Form component. The Form component encloses (wraps around) all the other field components such as TextField, TextArea, Checkbox, etc.

The Form component generates a number of component events that you may provide event handler methods for.

When rendering, the Form component emits two notifications: first, "prepareForRender", then "prepare". These allow the Form's container to setup any fields or properties that will be referenced in the form. For example, this is a good place to create a temporary entity object to be rendered, or to load an entity from a database to be edited.

When user submits the form on the client, a series of steps occur on the server.

First, the Form emits a "prepareForSubmit" notification, then a "prepare" notification. These allow the container to ensure that objects are set up and ready to receive information from the form submission.

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.

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.

After the fields have done their processing, the Form emits a "validateForm" event. This is a chance to perform cross-form validation that can't be described declaratively.

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.

Last, the Form emits a "submit" event (for logic that doesn't care about success or failure).

Tracking Validation Errors

Associated with the Form is an ValidationTracker that tracks all the provided user input and validation errors for every field in the form. The tracker can be provided to the Form via the Form's tracker parameter, but this is rarely necessary.

The Form includes methods isValid() and getHasErrors(), which are used to see if the Form's validation tracker contains any errors.

In your own logic, it is possible to record your own errors. Form includes two different versions of method recordError(), one of which specifies a Field (an interface implemented by all form element components), and one of which is for "global" errors, unassociated with any particular field.

Storing Data Between Requests

As with other action requests, the result of a form submission is to send a redirect to the client which re-renders the page. The ValidationTracker must be stored persistently between requests, or all the validation information will be lost (the default ValidationTracker provided by the Form is persistent).

Likewise, the individual fields updated by the components should also be persistent.

For example, a Login page, which collects a user name and a password, might look like:



public class Login
{
@Persist
private String userName;

private String password;

@Inject
private UserAuthenticator authenticator;

@Component(id = "password")
private PasswordField passwordField;

@Component
private Form form;

String onSuccess()
{
if (!authenticator.isValid(userName, password))
{

[CONF] Apache Tapestry Forms and Validation

2011-06-04 Thread confluence







Forms and Validation
Page edited by Bob Harner


Comment:
Added "forms" label to related articles, so FAQ would appear there


 Changes (1)
 




{float:right|background="" 
{contentbylabel:title=Related Articles|showLabels=false|showSpace=false|space=TAPESTRY|labels=validation,forms} 
{float}  
...


Full Content


Related Articles


 Page:
 Forms and Validation





 Page:
 Bean Validation





 Page:
 Forms and Form Components FAQ






The life's blood of any application is form input; this is the most effective way to gather significant information from the user. Whether it's a search form, a login screen or a multi-page registration wizard, forms are how the user really expresses themselves to the application.

Tapestry excels at creating forms and validating input. Input validation is declarative, meaning you simply tell Tapestry what validations to apply to a given field, and it takes care of it on the server and (once implemented) on the client as well.

Finally, Tapestry is able to not only present the errors back to the user, but to decorate the fields and the labels for the fields, marking them as containing errors (primarily, using CSS effects).

Form component

The core of Tapestry's form support is the Form component. The Form component encloses (wraps around) all the other field components such as TextField, TextArea, Checkbox, etc.

The Form component generates a number of component events that you may provide event handler methods for.

When rendering, the Form component emits two notifications: first, "prepareForRender", then "prepare". These allow the Form's container to setup any fields or properties that will be referenced in the form. For example, this is a good place to create a temporary entity object to be rendered, or to load an entity from a database to be edited.

When user submits the form on the client, a series of steps occur on the server.

First, the Form emits a "prepareForSubmit" notification, then a "prepare" notification. These allow the container to ensure that objects are set up and ready to receive information from the form submission.

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.

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.

After the fields have done their processing, the Form emits a "validateForm" event. This is a chance to perform cross-form validation that can't be described declaratively.

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.

Last, the Form emits a "submit" event (for logic that doesn't care about success or failure).

Tracking Validation Errors

Associated with the Form is an ValidationTracker that tracks all the provided user input and validation errors for every field in the form. The tracker can be provided to the Form via the Form's tracker parameter, but this is rarely necessary.

The Form includes methods isValid() and getHasErrors(), which are used to see if the Form's validation tracker contains any errors.

In your own logic, it is possible to record your own errors. Form includes two different versions of method recordError(), one of which specifies a Field (an interface implemented by all form element components), and one of which is for "global" errors, unassociated with any particular field.

Storing Data Between Requests

As with other action requests, the result of a form submission is to send a redirect to the client which re-renders the page. The ValidationTracker must be stored persistently between requests, or all the validation information will be lost (the default ValidationTracker provided by the Form is persistent).

Likewise, the individual fields updated by the components should also be persistent.

For example, a Login page, which collects a user name and a password, might look like:



public class Login
{
@Persist
private String