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, 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:
- If the passed value is
null
, exit immediately. -
If the passed value is not a String, exit with a
NOT_MATCHED_MESSAGE_ID
error message. -
If no pattern has been set, or pattern resolves to
null
or an empty String, throw aValidatorException
with aPATTERN_NOT_SET_MESSAGE_ID
message. -
If pattern is not a valid regular expression, according to the rules as defined
in class
Pattern
, throw aValidatorException
with a (@link #MATCH_EXCEPTION_MESSAGE_ID} message. -
If a
pattern
property has been configured on thisValidator
, check the passed value against this pattern. If value does not match pattern throw aValidatorException
containing aNOT_MATCHED_MESSAGE_ID
message.
- Since:
- 2.0
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
This message ID is used when the pattern is not a valid regular expression, according to the rules as defined in classPattern
static final String
This message ID is used when the passed value is not a String, or when the pattern does not match the passed value.static final String
This message ID is used when the pattern isnull
, or an empty String.static final String
Converter ID, as defined by the Faces 2.0 specification. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Return the ValueExpression that yields the regular expression pattern when evaluated.boolean
boolean
void
void
restoreState
(FacesContext context, Object state) 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)
-
Field Details
-
VALIDATOR_ID
Converter ID, as defined by the Faces 2.0 specification.- See Also:
-
PATTERN_NOT_SET_MESSAGE_ID
This message ID is used when the pattern isnull
, or an empty String.- See Also:
-
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:
-
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:
-
-
Constructor Details
-
RegexValidator
public RegexValidator()
-
-
Method Details
-
validate
-
saveState
- Specified by:
saveState
in interfaceStateHolder
-
restoreState
- Specified by:
restoreState
in interfaceStateHolder
-
isTransient
public boolean isTransient()- Specified by:
isTransient
in interfaceStateHolder
-
setTransient
public void setTransient(boolean isTransient) - Specified by:
setTransient
in interfaceStateHolder
-
setPattern
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
Return the ValueExpression that yields the regular expression pattern when evaluated.- Returns:
- The pattern.
-
clearInitialState
public void clearInitialState()- Specified by:
clearInitialState
in interfacePartialStateHolder
-
initialStateMarked
public boolean initialStateMarked()- Specified by:
initialStateMarked
in interfacePartialStateHolder
-
markInitialState
public void markInitialState()- Specified by:
markInitialState
in interfacePartialStateHolder
-