com.ibm.xsp.validator
Class LengthValidatorEx

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

public class LengthValidatorEx
extends javax.faces.validator.LengthValidator
implements ValueBindingObject, ComponentBindingObject, ClientSideValidator

Extends the standard length validator to add support for automatic client-side validation and computed expressions on it's properties. Corresponds to the xp:validateLength tag


Field Summary
 
Fields inherited from class javax.faces.validator.LengthValidator
MAXIMUM_MESSAGE_ID, MINIMUM_MESSAGE_ID, VALIDATOR_ID
 
Fields inherited from interface javax.faces.validator.Validator
NOT_IN_RANGE_MESSAGE_ID
 
Constructor Summary
LengthValidatorEx()
           
 
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.
 javax.faces.component.UIComponent getComponent()
          Return the associated UIComponent instance.
 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.
 int getMaximum()
           
 java.lang.String getMessage()
          Validation error message to be displayed to the user
 int getMinimum()
           
 javax.faces.el.ValueBinding getValueBinding(java.lang.String property)
          Return the ValueBinding instance to used to calculate the value for the specified property.
 void restoreState(javax.faces.context.FacesContext context, java.lang.Object state)
           
 java.lang.Object saveState(javax.faces.context.FacesContext context)
           
 void setComponent(javax.faces.component.UIComponent component)
          This will be called while constructing the component and the UIComponent tree, so no processing should be performed at this stage.
 void setMaximum(int maximum)
           
 void setMessage(java.lang.String message)
          Sets the validation error message to be displayed to the user
 void setMinimum(int minimum)
           
 void setValueBinding(java.lang.String property, javax.faces.el.ValueBinding binding)
          Set the ValueBinding instance to used to calculate the value for the specified property.
 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.
 
Methods inherited from class javax.faces.validator.LengthValidator
equals, isTransient, setTransient
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LengthValidatorEx

public LengthValidatorEx()
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
Overrides:
validate in class javax.faces.validator.LengthValidator
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.FacesException
javax.faces.validator.ValidatorException

setComponent

public void setComponent(javax.faces.component.UIComponent component)
Description copied from interface: ComponentBindingObject
This will be called while constructing the component and the UIComponent tree, so no processing should be performed at this stage.

Specified by:
setComponent in interface ComponentBindingObject

getComponent

public javax.faces.component.UIComponent getComponent()
Description copied from interface: ComponentBindingObject
Return the associated UIComponent instance.

Specified by:
getComponent in interface ComponentBindingObject
Returns:
the associated UIComponent instance

setMaximum

public void setMaximum(int maximum)
Overrides:
setMaximum in class javax.faces.validator.LengthValidator

getMaximum

public int getMaximum()
Overrides:
getMaximum in class javax.faces.validator.LengthValidator

setMinimum

public void setMinimum(int minimum)
Overrides:
setMinimum in class javax.faces.validator.LengthValidator

getMinimum

public int getMinimum()
Overrides:
getMinimum in class javax.faces.validator.LengthValidator

getMessage

public java.lang.String getMessage()
Validation error message to be displayed to the user

Returns:
validation error message

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.

setMessage

public void setMessage(java.lang.String message)
Sets the validation error message to be displayed to the user

Set the value of the message property.


getValueBinding

public javax.faces.el.ValueBinding getValueBinding(java.lang.String property)
Description copied from interface: ValueBindingObject
Return the ValueBinding instance to used to calculate the value for the specified property.

Specified by:
getValueBinding in interface ValueBindingObject
Parameters:
property - Name of the property
Returns:
ValueBinding instance to used to calculate the value for the specified property

setValueBinding

public void setValueBinding(java.lang.String property,
                            javax.faces.el.ValueBinding binding)
Description copied from interface: ValueBindingObject
Set the ValueBinding instance to used to calculate the value for the specified property.

Specified by:
setValueBinding in interface ValueBindingObject
Parameters:
property - Name of the property
binding - The ValueBinding to set, or null to remove an existing ValueBinding

saveState

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

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 javax.faces.validator.LengthValidator

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