javax.faces.validator
Class RegexValidator

java.lang.Object
  extended by javax.faces.validator.RegexValidator
All Implemented Interfaces:
EventListener, PartialStateHolder, StateHolder, Validator

@JSFValidator(name="f:validateRegex",
              bodyContent="empty",
              tagClass="org.apache.myfaces.taglib.core.ValidateRegexTag")
@JSFJspProperty(name="binding",
                returnType="javax.faces.validator.RegexValidator",
                longDesc="A ValueExpression that evaluates to a RegexValidator.")
public class RegexValidator
extends Object
implements Validator, PartialStateHolder

RegexValidator 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 RegexValidator class is same as mentioned in class Pattern in package java.util.regex.

The following algorithm is implemented:

Since:
2.0
Author:
Jan-Kees van Andel

Field Summary
static String MATCH_EXCEPTION_MESSAGE_ID
          This message ID is used when the pattern is not a valid regular expression, according to the rules as defined in class Pattern
static String NOT_MATCHED_MESSAGE_ID
          This message ID is used when the passed value is not a String, or when the pattern does not match the passed value.
static String PATTERN_NOT_SET_MESSAGE_ID
          This message ID is used when the pattern is null, or an empty String.
static String VALIDATOR_ID
          Converter ID, as defined by the JSF 2.0 specification.
 
Fields inherited from interface javax.faces.validator.Validator
NOT_IN_RANGE_MESSAGE_ID
 
Constructor Summary
RegexValidator()
           
 
Method Summary
 void clearInitialState()
           
 String getPattern()
          Return the ValueExpression that yields the regular expression pattern when evaluated.
 boolean initialStateMarked()
           
 boolean isTransient()
          
 void markInitialState()
           
 void restoreState(FacesContext context, Object state)
          
 Object saveState(FacesContext context)
          
 void setPattern(String pattern)
          The Regular Expression property to validate against.
 void setTransient(boolean isTransient)
          
 void validate(FacesContext context, UIComponent component, Object value)
          
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VALIDATOR_ID

public static final String VALIDATOR_ID
Converter ID, as defined by the JSF 2.0 specification.

See Also:
Constant Field Values

PATTERN_NOT_SET_MESSAGE_ID

public static final String PATTERN_NOT_SET_MESSAGE_ID
This message ID is used when the pattern is null, or an empty String.

See Also:
Constant Field Values

NOT_MATCHED_MESSAGE_ID

public static final String NOT_MATCHED_MESSAGE_ID
This message ID is used when the passed value is not a String, or when the pattern does not match the passed value.

See Also:
Constant Field Values

MATCH_EXCEPTION_MESSAGE_ID

public static final String MATCH_EXCEPTION_MESSAGE_ID
This message ID is used when the pattern is not a valid regular expression, according to the rules as defined in class Pattern

See Also:
Constant Field Values
Constructor Detail

RegexValidator

public RegexValidator()
Method Detail

validate

public void validate(FacesContext context,
                     UIComponent component,
                     Object value)

Specified by:
validate in interface Validator

saveState

public Object saveState(FacesContext context)

Specified by:
saveState in interface StateHolder

restoreState

public void restoreState(FacesContext context,
                         Object state)

Specified by:
restoreState in interface StateHolder

isTransient

public boolean isTransient()

Specified by:
isTransient in interface StateHolder

setTransient

public void setTransient(boolean isTransient)

Specified by:
setTransient in interface StateHolder

setPattern

public void setPattern(String pattern)
The Regular Expression property to validate against. This property must be a ValueExpression that resolves to a String in the format of the java.util.regex patterns.

Parameters:
pattern - a ValueExpression that evaluates to a String that is the regular expression pattern

getPattern

@JSFProperty(required=true)
public String getPattern()
Return the ValueExpression that yields the regular expression pattern when evaluated.

Returns:
The pattern.

clearInitialState

public void clearInitialState()
Specified by:
clearInitialState in interface PartialStateHolder

initialStateMarked

public boolean initialStateMarked()
Specified by:
initialStateMarked in interface PartialStateHolder

markInitialState

public void markInitialState()
Specified by:
markInitialState in interface PartialStateHolder


Copyright © 2015 The Apache Software Foundation. All Rights Reserved.