com.smartgwt.client.widgets.form.validator
Class Validator

java.lang.Object
  extended by com.smartgwt.client.core.JsObject
      extended by com.smartgwt.client.core.DataClass
          extended by com.smartgwt.client.widgets.form.validator.Validator
Direct Known Subclasses:
ContainsValidator, CustomValidator, DateRangeValidator, DoesntContainValidator, FloatPrecisionValidator, FloatRangeValidator, IntegerRangeValidator, IsBooleanValidator, IsFloatValidator, IsIntegerValidator, IsOneOfValidator, IsStringValidator, LengthRangeValidator, MaskValidator, MatchesFieldValidator, RegExpValidator, RequiredIfValidator, StringCountValidator

public class Validator
extends DataClass

A validator describes a check that should be performed on a value the user is trying to save.

Validators are specified for DataSource fields via the validators property. Validators that need not be run on the server can also be specified for a specific FormItem or ${isc.DocUtils.linkForRef('object:ListGridField')}.

Smart GWT supports a powerful library of com.smartgwt.client..ValidatorTypes which have identical behavior 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 com.smartgwt.client.widgets.form.validator.Validator#addValidator method.


Field Summary
 
Fields inherited from class com.smartgwt.client.core.JsObject
jsObj
 
Constructor Summary
Validator()
           
Validator(JavaScriptObject jsObj)
           
 
Method Summary
 Boolean getClientOnly()
          Indicates this validator runs on the client only.
static Validator getOrCreateRef(JavaScriptObject jsObj)
           
 String getServerCondition()
          An expression in the Velocity Template Language that will run on the server.
 Boolean getServerOnly()
          Indicates this validator runs on the server only.
 Boolean getStopIfFalse()
          Normally, all validators defined for a field will be run even if one of the validators has already failed.
 void setClientOnly(Boolean clientOnly)
          Indicates this validator runs on the client only.
 void setErrorMessage(String errorMessage)
          Text to display if the value does not pass this validation check.
 void setServerCondition(String serverCondition)
          An expression in the Velocity Template Language that will run on the server.
 void setServerOnly(Boolean serverOnly)
          Indicates this validator runs on the server only.
 void setStopIfFalse(Boolean stopIfFalse)
          Normally, all validators defined for a field will be run even if one of the validators has already failed.
 
Methods inherited from class com.smartgwt.client.core.DataClass
doAddHandler, fireEvent, getAttribute, getAttributeAsBoolean, getAttributeAsDate, getAttributeAsDouble, getAttributeAsFloat, getAttributeAsInt, getAttributeAsIntArray, getAttributeAsJavaScriptObject, getAttributeAsMap, getAttributeAsObject, getAttributeAsString, getAttributeAsStringArray, getAttributes, getHandlerCount, getJsObj, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute
 
Methods inherited from class com.smartgwt.client.core.JsObject
isCreated, setJsObj
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Validator

public Validator()

Validator

public Validator(JavaScriptObject jsObj)
Method Detail

getOrCreateRef

public static Validator getOrCreateRef(JavaScriptObject jsObj)

setStopIfFalse

public void setStopIfFalse(Boolean stopIfFalse)
Normally, all validators defined for a field will be run even if one of the validators has already failed. However, if stopIfFalse is set, validation will not proceed beyond this validator if the check fails.

This is useful to prevent expensive validators from being run unnecessarily, or to allow custom validators that don't need to be robust about handling every conceivable type of value.

Parameters:
stopIfFalse - stopIfFalse Default value is false

getStopIfFalse

public Boolean getStopIfFalse()
Normally, all validators defined for a field will be run even if one of the validators has already failed. However, if stopIfFalse is set, validation will not proceed beyond this validator if the check fails.

This is useful to prevent expensive validators from being run unnecessarily, or to allow custom validators that don't need to be robust about handling every conceivable type of value.

Returns:
Boolean

setClientOnly

public void setClientOnly(Boolean clientOnly)
Indicates this validator runs on the client only.

Normally, if the server is trying to run validators and finds a validator that it can't execute, for safety reasons validation is considered to have failed. Use this flag to explicitly mark a validator that only needs to run on the client.

Parameters:
clientOnly - clientOnly Default value is false

getClientOnly

public Boolean getClientOnly()
Indicates this validator runs on the client only.

Normally, if the server is trying to run validators and finds a validator that it can't execute, for safety reasons validation is considered to have failed. Use this flag to explicitly mark a validator that only needs to run on the client.

Returns:
Boolean

setServerOnly

public void setServerOnly(Boolean serverOnly)
Indicates this validator runs on the server only.

Parameters:
serverOnly - serverOnly Default value is null

getServerOnly

public Boolean getServerOnly()
Indicates this validator runs on the server only.

Returns:
Boolean

setServerCondition

public void setServerCondition(String serverCondition)
An expression in the Velocity Template Language that will run on the server. Unlike most other Smart GWT Server features involving Velocity, server-side custom validators do not have access to the standard set of context variables. This is deliberate, to ensure that custom validators can run in the widest possible variety of circumstances, without being tied to operating in the context of, say, an HttpSession or a DSRequest. Server-side custom validators only have the following variables available:

Parameters:
serverCondition - Velocity Expression serverCondition Default value is null

getServerCondition

public String getServerCondition()
An expression in the Velocity Template Language that will run on the server. Unlike most other Smart GWT Server features involving Velocity, server-side custom validators do not have access to the standard set of context variables. This is deliberate, to ensure that custom validators can run in the widest possible variety of circumstances, without being tied to operating in the context of, say, an HttpSession or a DSRequest. Server-side custom validators only have the following variables available:

Returns:
Velocity Expression serverCondition

setErrorMessage

public void setErrorMessage(String errorMessage)
Text to display if the value does not pass this validation check.

If unspecified, default error messages exist for all built-in validators, and a generic message will be used for a custom validator that is not passed.

Parameters:
errorMessage - errorMessage Default value is null