com.ibm.xsp.validator
Class ConstraintValidator

java.lang.Object
  extended by com.ibm.xsp.complex.ValueBindingObjectImpl
      extended by com.ibm.xsp.validator.AbstractValidator
          extended by com.ibm.xsp.validator.ConstraintValidator
All Implemented Interfaces:
ComponentBindingObject, ValueBindingObject, ClientSideValidator, java.util.EventListener, javax.faces.component.StateHolder, javax.faces.validator.Validator

public class ConstraintValidator
extends AbstractValidator
implements ClientSideValidator

Validates a value using an regular expression. Corresponds to the xp:validateConstraint tag.


Field Summary
static java.lang.String REGEX_ALNUMONLY
          Used to check if expression is Alphabet and Number only
static java.lang.String REGEX_ALPHABETONLY
          Used to check if expression is Alphabet only
static java.lang.String REGEX_DIGITONLY
          Used to check if expression is Digit only
 
Fields inherited from interface javax.faces.validator.Validator
NOT_IN_RANGE_MESSAGE_ID
 
Constructor Summary
ConstraintValidator()
           
 
Method Summary
 java.lang.String generateClientSideValidation(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component)
          Generate client side validation, a snippet of browser JavaScript in a single line, creating an instance of a Validator object matching the format described in xspClientDojo.js, the attachValidator function.
 java.lang.String getInvalidMessage()
          Unlike server-side validators which display different error messages depending on the exact way that validation fails, client side validators usually have only one error message.
 java.lang.String getRegex()
          Returns the regular expression that is to be performed on users input
 void restoreState(javax.faces.context.FacesContext context, java.lang.Object state)
           
 java.lang.Object saveState(javax.faces.context.FacesContext context)
           
 void setRegex(java.lang.String regex)
          Sets the the regular expression which is specified to limit the type of characters that the user can input.
 void validate(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component, java.lang.Object value)
          Perform the correctness checks implemented by this Validator against the specified UIInput.
protected  void validateAlnumOnly(java.lang.String convertedValue, javax.faces.context.FacesContext context, javax.faces.component.UIInput component)
          Protected method.
protected  void validateAlphabetOnly(java.lang.String convertedValue, javax.faces.context.FacesContext context, javax.faces.component.UIInput component)
          Protected method.
protected  void validateDigitOnly(java.lang.String convertedValue, javax.faces.context.FacesContext context, javax.faces.component.UIInput component)
          Protected method.
protected  void validateRegEx(java.lang.String convertedValue, javax.faces.context.FacesContext context, javax.faces.component.UIInput component)
          Protected method.
 
Methods inherited from class com.ibm.xsp.validator.AbstractValidator
addInputInvalidMessage, createNullContextOrComponentEx, createValidatorEx, getInvalidRangeMessage, getMessage, getNotCorrectTypeMessage, setMessage
 
Methods inherited from class com.ibm.xsp.complex.ValueBindingObjectImpl
getComponent, getFacesContext, getValueBinding, isTransient, setComponent, setTransient, setValueBinding
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

REGEX_ALPHABETONLY

public static final java.lang.String REGEX_ALPHABETONLY
Used to check if expression is Alphabet only

See Also:
Constant Field Values

REGEX_DIGITONLY

public static final java.lang.String REGEX_DIGITONLY
Used to check if expression is Digit only

See Also:
Constant Field Values

REGEX_ALNUMONLY

public static final java.lang.String REGEX_ALNUMONLY
Used to check if expression is Alphabet and Number only

See Also:
Constant Field Values
Constructor Detail

ConstraintValidator

public ConstraintValidator()
Method Detail

validate

public void validate(javax.faces.context.FacesContext context,
                     javax.faces.component.UIComponent component,
                     java.lang.Object value)
              throws javax.faces.validator.ValidatorException

Perform the correctness checks implemented by this Validator against the specified UIInput. If any violations are found:

Specified by:
validate in interface javax.faces.validator.Validator
Parameters:
context - FacesContext for the request we are processing
component - UIInput we are checking for correctness
value - to be validated
Throws:
java.lang.NullPointerException - if context or component is null
javax.faces.validator.ValidatorException

getInvalidMessage

public java.lang.String getInvalidMessage()
Description copied from interface: ClientSideValidator
Unlike server-side validators which display different error messages depending on the exact way that validation fails, client side validators usually have only one error message. For example, you might have server-side messages "Value is less than minimum {0}" and "Value is greater than maximum {1}", but client-side you would only have one message "Value is not in the allowed range {0} to {1}".

This method may return different values depending on the configuration of the validator.

Specified by:
getInvalidMessage in interface ClientSideValidator
Returns:
message to display when the value is invalid.

validateAlphabetOnly

protected void validateAlphabetOnly(java.lang.String convertedValue,
                                    javax.faces.context.FacesContext context,
                                    javax.faces.component.UIInput component)
Protected method. Subject to change and is used at your own risk


validateDigitOnly

protected void validateDigitOnly(java.lang.String convertedValue,
                                 javax.faces.context.FacesContext context,
                                 javax.faces.component.UIInput component)
Protected method. Subject to change and is used at your own risk


validateAlnumOnly

protected void validateAlnumOnly(java.lang.String convertedValue,
                                 javax.faces.context.FacesContext context,
                                 javax.faces.component.UIInput component)
Protected method. Subject to change and is used at your own risk


validateRegEx

protected void validateRegEx(java.lang.String convertedValue,
                             javax.faces.context.FacesContext context,
                             javax.faces.component.UIInput component)
Protected method. Subject to change and is used at your own risk


getRegex

public java.lang.String getRegex()
Returns the regular expression that is to be performed on users input

Returns:
regular expression

setRegex

public void setRegex(java.lang.String regex)
Sets the the regular expression which is specified to limit the type of characters that the user can input. Examples: [A-Za-z]* : Alphabet characters only. [0-9]* : Digits only. [A-Za-z]{2,4} : Alphabet characters, between 2 and 4 characters in length, only.

Parameters:
string -

saveState

public java.lang.Object saveState(javax.faces.context.FacesContext context)
Specified by:
saveState in interface javax.faces.component.StateHolder
Overrides:
saveState in class AbstractValidator

restoreState

public void restoreState(javax.faces.context.FacesContext context,
                         java.lang.Object state)
Specified by:
restoreState in interface javax.faces.component.StateHolder
Overrides:
restoreState in class AbstractValidator

generateClientSideValidation

public java.lang.String generateClientSideValidation(javax.faces.context.FacesContext context,
                                                     javax.faces.component.UIComponent component)
                                              throws java.io.IOException
Description copied from interface: ClientSideValidator
Generate client side validation, a snippet of browser JavaScript in a single line, creating an instance of a Validator object matching the format described in xspClientDojo.js, the attachValidator function.

The file xspClientDojo.js is reference in the source of every XPage. The version with comments is installed with Designer under the Data/domino/js folder, in a file named xspClientDojo.js.uncompressed.js.

The constructor of the Validator object should be passed any values needed to perform the validation (e.g. for a range validator the minimum and maximum values would be included). The translated error message to display if the error occurs should be passed to the validator too. Generally the server-side validators translate a default error message and allow the page designer to override the default in a "message" property.

Specified by:
generateClientSideValidation in interface ClientSideValidator
Parameters:
context - The current context.
component - The control whose value will be validated, usually a UIInput.
Returns:
snippet of browser JavaScript to create the Validator object.
Throws:
java.io.IOException