org.apache.myfaces.trinidad.validator

## Class RegExpValidator

- java.lang.Object
- - org.apache.myfaces.trinidad.validator.RegExpValidator

- All Implemented Interfaces:
    EventListener, javax.faces.component.StateHolder, javax.faces.validator.Validator

      public class RegExpValidator
      extends Object
      implements javax.faces.component.StateHolder, javax.faces.validator.Validator

  RegExpValidator is a `Validator` that checks the value of the corresponding component against specified pattern using Java regular expression syntax. The regular expression syntax accepted by the RegExpValidator class is same as mentioned in class `Pattern` in package `java.util.regex`. The following algorithm is implemented:

  - If the passed value is `null`, exit immediately.
  - If a `pattern` property has been configured on this `Validator`, check the component value against this pattern. If value does not match pattern throw a `ValidatorException` containing a NO_MATCH_MESSAGE_ID message. If `noMatchMessageDetail` is set, it is used for constructing faces message. The message can contain placeholders which will be replaced as specified in `NO_MATCH_MESSAGE_ID`
  Version:
    $Name: $ ($Revision: adfrt/faces/adf-faces-api/src/main/java/oracle/adf/view/faces/validator/RegExpValidator.java#0 $) $Date: 10-nov-2005.19:08:34 $
  See Also:
    `setMessageDetailNoMatch(String)`

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static String` | `NO_MATCH_MESSAGE_ID` The message identifier of the `FacesMessage` to be created if the match fails.
    `static String` | `VALIDATOR_ID` Standard validator id for this validator.

    - ### Fields inherited from interface javax.faces.validator.Validator

      `NOT_IN_RANGE_MESSAGE_ID`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `RegExpValidator()` Construct a RegExpValidator with no preconfigured pattern.
    `RegExpValidator(String pattern)` Construct a RegExpValidator with preconfigured pattern.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `equals(Object object)` Compares this PatternValidator with the specified Object for equality.
    `String` | `getHint()` Return custom hint message.
    `String` | `getMessageDetailNoMatch()` Return custom detail error message that was set for creating faces message, for values that do not match the specified pattern.
    `String` | `getPattern()` Return the pattern value to be enforced by this `Validator`
    `javax.faces.el.ValueBinding` | `getValueBinding(String name)` Deprecated.
    `javax.el.ValueExpression` | `getValueExpression(String name)` Return the `ValueExpression` used to calculate the value for the specified attribute name, if any.
    `int` | `hashCode()` Returns the hash code for this Validator.
    `boolean` | `isTransient()`
    `void` | `restoreState(javax.faces.context.FacesContext context, Object state)`
    `Object` | `saveState(javax.faces.context.FacesContext context)`
    `void` | `setHint(String hintPattern)` Custom hint message.
    `void` | `setMessageDetailNoMatch(String noMatchMessageDetail)` Custom error message to be used, for creating detail part of the `FacesMessage`, when value does not match the specified pattern.
    `void` | `setPattern(String pattern)` Set the pattern value to be enforced by this `Validator`
    `void` | `setTransient(boolean transientValue)`
    `void` | `setValueBinding(String name, javax.faces.el.ValueBinding binding)` Deprecated.
    `void` | `setValueExpression(String name, javax.el.ValueExpression expression)` Set the `ValueExpression` used to calculate the value for the specified attribute if any.
    `void` | `validate(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component, Object value)`

    - ### Methods inherited from class java.lang.Object

      `clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### VALIDATOR_ID

          public static final String VALIDATOR_ID

      Standard validator id for this validator.

      See Also:
        Constant Field Values

    - #### NO_MATCH_MESSAGE_ID

          public static final String NO_MATCH_MESSAGE_ID

      The message identifier of the `FacesMessage` to be created if the match fails. The message format string for this message may optionally include a `{0}`, `{1}` and `{4}` placeholders, which will be replaced input value, label associated with the component and pattern respectively.

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### RegExpValidator

          public RegExpValidator()

      Construct a RegExpValidator with no preconfigured pattern.

    - #### RegExpValidator

          public RegExpValidator(String pattern)

      Construct a RegExpValidator with preconfigured pattern.

  - ### Method Detail

    - #### validate

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

      Specified by:
        `validate` in interface `javax.faces.validator.Validator`
      Throws:
        `javax.faces.validator.ValidatorException` - if validation fails
        `NullPointerException` - if `context` or `component` or `pattern` is `null`
        `IllegalArgumentException` - if `value` is not of type `String`

    - #### isTransient

          public boolean isTransient()

      Specified by:
        `isTransient` in interface `javax.faces.component.StateHolder`

    - #### setTransient

          public void setTransient(boolean transientValue)

      Specified by:
        `setTransient` in interface `javax.faces.component.StateHolder`

    - #### saveState

          public Object saveState(javax.faces.context.FacesContext context)

      Specified by:
        `saveState` in interface `javax.faces.component.StateHolder`

    - #### restoreState

          public void restoreState(javax.faces.context.FacesContext context,
                          Object state)

      Specified by:
        `restoreState` in interface `javax.faces.component.StateHolder`

    - #### setValueExpression

          public void setValueExpression(String name,
                                javax.el.ValueExpression expression)

      Set the `ValueExpression` used to calculate the value for the specified attribute if any.

      Parameters:
        `name` - Name of the attribute for which to set a `ValueExpression`
        `expression` - The `ValueExpression` to set, or `null` to remove any currently set `ValueExpression`
      Throws:
        `NullPointerException` - if `name` is `null`
        `IllegalArgumentException` - if `name` is not a valid attribute of this converter

    - #### getValueExpression

          public javax.el.ValueExpression getValueExpression(String name)

      Return the `ValueExpression` used to calculate the value for the specified attribute name, if any.

      Parameters:
        `name` - Name of the attribute or property for which to retrieve a `ValueExpression`
      Throws:
        `NullPointerException` - if `name` is `null`
        `IllegalArgumentException` - if `name` is not a valid attribute of this converter

    - #### setValueBinding

          public void setValueBinding(String name,
                             javax.faces.el.ValueBinding binding)

      Deprecated.

      Set the `ValueBinding` used to calculate the value for the specified attribute if any.

      Parameters:
        `name` - Name of the attribute for which to set a `ValueBinding`
        `binding` - The `ValueBinding` to set, or `null` to remove any currently set `ValueBinding`
      Throws:
        `NullPointerException` - if `name` is `null`
        `IllegalArgumentException` - if `name` is not a valid attribute of this validator

    - #### getValueBinding

          public javax.faces.el.ValueBinding getValueBinding(String name)

      Deprecated.

      Return the `ValueBinding` used to calculate the value for the specified attribute name, if any.

      Parameters:
        `name` - Name of the attribute or property for which to retrieve a `ValueBinding`
      Throws:
        `NullPointerException` - if `name` is `null`
        `IllegalArgumentException` - if `name` is not a valid attribute of this validator

    - #### equals

          public boolean equals(Object object)

      Compares this PatternValidator with the specified Object for equality.

      Overrides:
        `equals` in class `Object`
      Parameters:
        `object` - Object to which this PatternValidator is to be compared.
      Returns:
        true if and only if the specified Object is a PatternValidator and if the values pattern and transient are equal.

    - #### hashCode

          public int hashCode()

      Returns the hash code for this Validator.

      Overrides:
        `hashCode` in class `Object`
      Returns:
        a hash code value for this object.

    - #### setHint

          public void setHint(String hintPattern)

      Custom hint message.

      Overrides default hint message
      Parameters:
        `hintPattern` - Custom hint message.

    - #### getHint

          public String getHint()

      Return custom hint message.

      Returns:
        Custom hint message.
      See Also:
        `setHint(String)`

    - #### setPattern

          public void setPattern(String pattern)

      Set the pattern value to be enforced by this `Validator`

      Parameters:
        `pattern` - to be enforced.

    - #### getPattern

          public String getPattern()

      Return the pattern value to be enforced by this `Validator`

    - #### setMessageDetailNoMatch

          public void setMessageDetailNoMatch(String noMatchMessageDetail)

      Custom error message to be used, for creating detail part of the `FacesMessage`, when value does not match the specified pattern.

      Overrides detail message identified by message id `NO_MATCH_MESSAGE_ID`
      Parameters:
        `noMatchMessageDetail` -

    - #### getMessageDetailNoMatch

          public String getMessageDetailNoMatch()

      Return custom detail error message that was set for creating faces message, for values that do not match the specified pattern.

      Returns:
        Custom error message
      See Also:
        `setMessageDetailNoMatch(String)`

Copyright © 2001-2016 The Apache Software Foundation. All Rights Reserved.