org.apache.tapestry.valid
Class PatternValidator

java.lang.Object
  extended by org.apache.tapestry.valid.BaseValidator
      extended by org.apache.tapestry.valid.PatternValidator
All Implemented Interfaces:
IValidator

public class PatternValidator
extends BaseValidator

The validator bean that provides a pattern validation service.

The actual pattern matching algorithm is provided by the PatternDelegate. This enables the user to provide custom pattern matching implementations. In the event a custom implementation is not provided, this validator will use the RegexpMatcher.

This validator has the ability to provide client side validation on demand. To enable client side validation simply set the clientScriptingEnabled property to true. The default implementation of the script will be in JavaScript and allows the user to override this with a custom implementation by setting the path to the custom script via setScriptPath(String).

Since:
3.0
Version:
$Id: PatternValidator.java 243791 2004-02-19 17:38:13Z hlship $
Author:
Harish Krishnaswamy

Field Summary
 
Fields inherited from class org.apache.tapestry.valid.BaseValidator
FIELD_SYMBOL, FORM_SYMBOL, FUNCTION_SYMBOL, VALIDATOR_SYMBOL
 
Constructor Summary
PatternValidator()
           
 
Method Summary
 String getEscapedPatternString()
          Returns the escaped sequence of the pattern string for rendering in the error message.
 PatternDelegate getPatternDelegate()
          Returns the custom pattern matcher if one is provided or creates and returns the default matcher laziliy.
 String getPatternNotMatchedMessage()
          Returns custom validation failure message.
 String getPatternString()
          Returns the pattern that this validator uses for validation.
 void renderValidatorContribution(IFormComponent field, IMarkupWriter writer, IRequestCycle cycle)
          This implementation does nothing.
 void setPatternDelegate(PatternDelegate patternDelegate)
          Allows for a custom implementation to do the pattern matching.
 void setPatternNotMatchedMessage(String message)
          Allows for a custom message to be set typically via the bean specification.
 void setPatternString(String pattern)
          Allows the user to change the validation pattern.
 void setScriptPath(String scriptPath)
          Allows for a custom implementation of the client side validation.
 Object toObject(IFormComponent field, String input)
          Converts input, submitted by the client, into an object value.
 String toString()
           
 String toString(IFormComponent field, Object value)
          Invoked during rendering to convert an object value (which may be null) to a String.
 
Methods inherited from class org.apache.tapestry.valid.BaseValidator
buildRequiredMessage, checkRequired, formatString, formatString, formatString, getPattern, getRequiredMessage, isClientScriptingEnabled, isRequired, processValidatorScript, setClientScriptingEnabled, setRequired, setRequiredMessage
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PatternValidator

public PatternValidator()
Method Detail

getPatternNotMatchedMessage

public String getPatternNotMatchedMessage()
Returns custom validation failure message. The default message comes from ValidationStrings.properties file for key pattern-not-matched.


getPatternString

public String getPatternString()
Returns the pattern that this validator uses for validation.


setPatternNotMatchedMessage

public void setPatternNotMatchedMessage(String message)
Allows for a custom message to be set typically via the bean specification.


setPatternString

public void setPatternString(String pattern)
Allows the user to change the validation pattern.


setPatternDelegate

public void setPatternDelegate(PatternDelegate patternDelegate)
Allows for a custom implementation to do the pattern matching. The default pattern matching is done with RegexpMatcher.


getPatternDelegate

public PatternDelegate getPatternDelegate()
Returns the custom pattern matcher if one is provided or creates and returns the default matcher laziliy.


toString

public String toString(IFormComponent field,
                       Object value)
Description copied from interface: IValidator
Invoked during rendering to convert an object value (which may be null) to a String. It is acceptible to return null. The string will be the VALUE attribute of the HTML text field.

See Also:
IValidator.toString(org.apache.tapestry.form.IFormComponent, java.lang.Object)

toObject

public Object toObject(IFormComponent field,
                       String input)
                throws ValidatorException
Description copied from interface: IValidator
Converts input, submitted by the client, into an object value. May return null if the input is null (and the required flag is false).

The input string will already have been trimmed. It may be null.

Throws:
ValidatorException - if the string cannot be converted into an object, or the object is not valid (due to other constraints).
See Also:
IValidator.toObject(org.apache.tapestry.form.IFormComponent, java.lang.String)

setScriptPath

public void setScriptPath(String scriptPath)
Allows for a custom implementation of the client side validation.


renderValidatorContribution

public void renderValidatorContribution(IFormComponent field,
                                        IMarkupWriter writer,
                                        IRequestCycle cycle)
Description copied from class: BaseValidator
This implementation does nothing. Subclasses may supply their own implementation.

Specified by:
renderValidatorContribution in interface IValidator
Overrides:
renderValidatorContribution in class BaseValidator
See Also:
IValidator.renderValidatorContribution(org.apache.tapestry.form.IFormComponent, org.apache.tapestry.IMarkupWriter, org.apache.tapestry.IRequestCycle)

getEscapedPatternString

public String getEscapedPatternString()
Returns the escaped sequence of the pattern string for rendering in the error message.


toString

public String toString()
Overrides:
toString in class Object