Package jakarta.faces.validator
Class RegexValidator
- java.lang.Object
-
- jakarta.faces.validator.RegexValidator
-
- All Implemented Interfaces:
PartialStateHolder,StateHolder,Validator,EventListener
@JSFValidator(name="f:validateRegex", bodyContent="empty") @JSFJspProperty(name="binding", returnType="jakarta.faces.validator.RegexValidator", longDesc="A ValueExpression that evaluates to a RegexValidator.") public class RegexValidator extends Object implements Validator, PartialStateHolderRegexValidator is a
Validatorthat 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 classPatternin packagejava.util.regex.The following algorithm is implemented:
- If the passed value is
null, exit immediately. -
If the passed value is not a String, exit with a
NOT_MATCHED_MESSAGE_IDerror message. -
If no pattern has been set, or pattern resolves to
nullor an empty String, throw aValidatorExceptionwith aPATTERN_NOT_SET_MESSAGE_IDmessage. -
If pattern is not a valid regular expression, according to the rules as defined
in class
Pattern, throw aValidatorExceptionwith a (@link #MATCH_EXCEPTION_MESSAGE_ID} message. -
If a
patternproperty has been configured on thisValidator, check the passed value against this pattern. If value does not match pattern throw aValidatorExceptioncontaining aNOT_MATCHED_MESSAGE_IDmessage.
- Since:
- 2.0
-
-
Field Summary
Fields Modifier and Type Field Description static StringMATCH_EXCEPTION_MESSAGE_IDThis message ID is used when the pattern is not a valid regular expression, according to the rules as defined in classPatternstatic StringNOT_MATCHED_MESSAGE_IDThis message ID is used when the passed value is not a String, or when the pattern does not match the passed value.static StringPATTERN_NOT_SET_MESSAGE_IDThis message ID is used when the pattern isnull, or an empty String.static StringVALIDATOR_IDConverter ID, as defined by the JSF 2.0 specification.
-
Constructor Summary
Constructors Constructor Description RegexValidator()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclearInitialState()StringgetPattern()Return the ValueExpression that yields the regular expression pattern when evaluated.booleaninitialStateMarked()booleanisTransient()voidmarkInitialState()voidrestoreState(FacesContext context, Object state)ObjectsaveState(FacesContext context)voidsetPattern(String pattern)The Regular Expression property to validate against.voidsetTransient(boolean isTransient)voidvalidate(FacesContext context, UIComponent component, Object value)
-
-
-
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 isnull, 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 classPattern- See Also:
- Constant Field Values
-
-
Method Detail
-
validate
public void validate(FacesContext context, UIComponent component, Object value)
-
saveState
public Object saveState(FacesContext context)
- Specified by:
saveStatein interfaceStateHolder
-
restoreState
public void restoreState(FacesContext context, Object state)
- Specified by:
restoreStatein interfaceStateHolder
-
isTransient
public boolean isTransient()
- Specified by:
isTransientin interfaceStateHolder
-
setTransient
public void setTransient(boolean isTransient)
- Specified by:
setTransientin interfaceStateHolder
-
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:
clearInitialStatein interfacePartialStateHolder
-
initialStateMarked
public boolean initialStateMarked()
- Specified by:
initialStateMarkedin interfacePartialStateHolder
-
markInitialState
public void markInitialState()
- Specified by:
markInitialStatein interfacePartialStateHolder
-
-