short-circuiting and Validator flavors
Plain validator takes precedence over field-validator. They get validated first in the order they are defined and then the field-validator in the order they are defined. Failure of a particular validator marked as short-circuit will prevent the evaluation of subsequent validators and an error (action error or field error depending on the type of validator) will be added to the ValidationContext of the object being validated.
In the example above, the actual execution of validator would be as follows:
Since Plain Validator 2 is short-circuited, if its validation failed, it will causes Field validators for email field and Field validators for email2 field to not be validated as well.
Usefull Information: More complicated validation should probably be done in the validate() method on the action itself (assuming the action implements Validatable interface which ActionSupport already does).
A plain Validator (non FieldValidator) that gets short-circuited will completely break out of the validation stack. No other validators will be evaluated and plain validators takes precedence over field validators meaning that they get evaluated in the order they are defined before field validators get a chance to be evaluated.
Short cuircuiting and validator flavours
A FieldValidator that gets short-circuited will only prevent other FieldValidators for the same field from being evaluated. Note that this "same field" behavior applies regardless of whether the
<validator type="required" short-circuit="true"> <param name="fieldName">bar</param> <message>You must enter a value for bar.</message> </validator> <validator type="expression"> <param name="expression">foo gt bar</param> <message>foo must be great than bar.</message> </validator>
both validators will be run, even if the "required" validator short-circuits. "required" validators are FieldValidator's and will not short-circuit the plain ExpressionValidator because FieldValidators only short-circuit other checks on that same field. Since the plain Validator is not field specific, it is not short-circuited.
As mentioned above, the framework will also search up the inheritance tree of the action to find default validations for interfaces and parent classes of the Action. If you are using the short-circuit attribute and relying on default validators higher up in the inheritance tree, make sure you don't accidentally short-circuit things higher in the tree that you really want!
The effect of having common validators on both
It should be noted that the nett effect will be validation on both the validators available in both validation configuration file. For example if we have 'requiredstring' validators defined in both validation xml file for field named 'address', we will see 2 validation error indicating that the the address cannot be empty (assuming validation failed). This is due to WebWork will merge validators found in both validation configuration files.
The logic behind this design decision is such that we could have common validators in <actionClass>-validation.xml and more context specific validators to be located in <actionClass>-<actionAlias>-validation.xml
Validator's validation messages could be internatinalized. For example,<field-validator type="required"> <message key="required.field" /> </field-validator>or
<validator type="expression"> <param name="expression">email.startsWith('Mark')</param> <message key="email.invalid" /> </validator>In the first case, WebWork would look for i18n with key 'required.field' as the validation error message if validation fails, and 'email.invalid' in the second case. We could also provide a default message such that if validation failed and the i18n key for the message cannot be found, WebWork would fall back and use the default message. An example would be as follows :-
<field-validator type="required"> <message key="required.field">This field is required.</message> </field-validator>or
<validator type="expression"> <param name="expression">email.startsWith('Mark')</param> <message key="email.invalid">Email needs with starts with Mark</message> </validator>@author Jason Carreira
Validators are specified for DataSource fields via the {@link com.smartgwt.client.data.DataSourceField#getValidators validators}property. Validators that need not be run on the server can also be specified for a specific {@link com.smartgwt.client.widgets.form.fields.FormItem} or {@link com.smartgwt.client.widgets.grid.ListGridField}.
Smart GWT supports a powerful library of {@link com.smartgwt.client.types.ValidatorType ValidatorTypes} which have identicalbehavior on both the client and the server.
Beyond this, custom validators can be defined on the client and custom validation logic added on the server. Note that the regexp
and mask
validator types are very flexible and can be used to perform virtually any kind of formatting check that doesn't involve some large external dataset.
Custom validators can be reused on the client by adding them to the global validator list, via the {@link com.smartgwt.client.widgets.form.validator.Validator#addValidator Validator.addValidator} method. @see com.smartgwt.client.types.ValidatorType
Implementors of this class can be added to any {@link com.vaadin.data.Validatable Validatable} implementor to verify itsvalue.
{@link #validate(Object)} can be used to check if a value is valid. An{@link InvalidValueException} with an appropriate validation error message isthrown if the value is not valid.
Validators must not have any side effects.
Since Vaadin 7, the method isValid(Object) does not exist in the interface - {@link #validate(Object)} should be used instead, and the exception caughtwhere applicable. Concrete classes implementing {@link Validator} can stillinternally implement and use isValid(Object) for convenience or to ease migration from earlier Vaadin versions.
@author Vaadin Ltd. @since 3.0Model Objects are not required to use this interface when validating data, but it is often convenient to do so. In combination with {@link Check}, this interface is meant to reduce code repetition related to validation.
This interface is appropriate only for checks on a single field.
Please see {@link Check} for more information, and for some useful implementations.
A processor that checks an XML document against {@link Schema}.
A validator is a thread-unsafe and non-reentrant object. In other words, it is the application's responsibility to make sure that one {@link Validator} object is not used frommore than one thread at any given time, and while the validate method is invoked, applications may not recursively call the validate method.
Note that while the {@link #validate(javax.xml.transform.Source)} and {@link #validate(javax.xml.transform.Source,javax.xml.transform.Result)}methods take a {@link Source} instance, the Source
instance must be a SAXSource
or DOMSource
.
@author Kohsuke Kawaguchi
@version $Revision: 226183 $, $Date: 2005-04-08 06:39:14 -0400 (Fri, 08 Apr 2005) $
@since 1.5
ValidatorResources
is used to define the validators (validation methods) and the validation rules for a JavaBean.
@version $Revision: 478345 $ $Date: 2006-11-22 22:25:19 +0000 (Wed, 22 Nov 2006) $
This is indicated visually to the user (a red background would be typical), and events are fired by the TextInput if the programmer wishes to take further action.
This is indicated visually to the user (a red background would be typical), and events are fired by the TextInput if the programmer wishes to take further action.
Provides access to feature validation and integrity validation.
Feature validation will iterate over a feature features and test all features that have a validation test specific to them in the validation processor passed in.
Integrity validation will iterate over all data stores passed in through the stores map and run the tests associated with each store.
DOCUMENT ME!!
The following features are supported:
Validators
which uses raw form values. In this case, the parameterized type should be assignable from the type of the form propertyValidators
which use converted form values. In this case, validator needs to be used in conjunction with a Converter
. At least one of the validators should be parameterized to the actual conversion type (e.g. Integer
). Other validators can be parameterized to types assignable from the type of the converted value of the form property This is indicated visually to the user (a red background would be typical), and events are fired by the TextInput if the programmer wishes to take further action. @author Noel Grandin
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|