Top Description Fields Constructors Methods
javax.faces.validator

public Class RegexValidator

extends Object
implements Validator, PartialStateHolder
Class Inheritance
All Implemented Interfaces
javax.faces.component.PartialStateHolder, javax.faces.component.StateHolder, javax.faces.validator.Validator, java.util.EventListener
Imports
javax.faces.context.FacesContext, javax.faces.component.UIComponent, .PartialStateHolder, javax.faces.application.FacesMessage, java.util.Locale, java.util.regex.Matcher, .Pattern, .PatternSyntaxException

A Validator that checks against a Regular Expression (which is the pattern property). The pattern must resolve to a String that follows the java.util.regex standards.

Since
2.0

Field Summary

Modifier and TypeField and Description
private boolean
public static final String
MATCH_EXCEPTION_MESSAGE_ID

The message identifier of the javax.faces.application.FacesMessage to be created if the act of matching the value against the pattern returned from getPattern fails because of a PatternSyntaxException.

public static final String
NOT_MATCHED_MESSAGE_ID

The message identifier of the javax.faces.application.FacesMessage to be created if the act of matching the value against the pattern returned from getPattern fails because the value does not match the pattern.

public static final String
PATTERN_NOT_SET_MESSAGE_ID

The message identifier of the javax.faces.application.FacesMessage to be created if the value returned from getPattern is null or the empty String.

private String
private boolean
public static final String
VALIDATOR_ID

The standard converter id for this converter.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
clearInitialState()

Implements javax.faces.component.PartialStateHolder.clearInitialState.

Reset the PartialStateHolder to a non-delta tracking state.

public String

Returns:

the pattern
getPattern
()

Return the ValueExpression that yields the regular expression pattern when evaluated.

public boolean
initialStateMarked()

Implements javax.faces.component.PartialStateHolder.initialStateMarked.

Return true if delta state changes are being tracked, otherwise false

public boolean
isTransient()

Implements javax.faces.component.StateHolder.isTransient.

If true, the Object implementing this interface must not participate in state saving or restoring.

public void
markInitialState()

Implements javax.faces.component.PartialStateHolder.markInitialState.

The runtime must ensure that the markInitialState method is called on each instance of this interface in the view at the appropriate time to indicate the component is in its initial state.

public void
restoreState(FacesContext
the Faces context.
context
,
Object
the state.
state
)

Implements javax.faces.component.StateHolder.restoreState.

Perform any processing required to restore the state from the entries in the state Object.

public Object
saveState(FacesContext
the Faces context.
context
)

Implements javax.faces.component.StateHolder.saveState.

Gets the state of the instance as a Serializable Object.

public void
setPattern(String
a regular expression pattern
pattern
)

The Regular Expression property to validate against.

public void
setTransient(boolean
boolean pass true if this Object will not participate in state saving or restoring, otherwise pass false.
transientValue
)

Implements javax.faces.component.StateHolder.setTransient.

Denotes whether or not the Object implementing this interface must or must not participate in state saving or restoring.

public void
validate(FacesContext
FacesContext for the request we are processing
context
,
UIComponent
UIComponent we are checking for correctness
component
,
Object
the value to validate
value
)

Implements javax.faces.validator.Validator.validate.

Validate a String against a regular expression pattern.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

initialStateback to summary
private boolean initialState
MATCH_EXCEPTION_MESSAGE_IDback to summary
public static final String MATCH_EXCEPTION_MESSAGE_ID

The message identifier of the javax.faces.application.FacesMessage to be created if the act of matching the value against the pattern returned from getPattern fails because of a PatternSyntaxException.

NOT_MATCHED_MESSAGE_IDback to summary
public static final String NOT_MATCHED_MESSAGE_ID

The message identifier of the javax.faces.application.FacesMessage to be created if the act of matching the value against the pattern returned from getPattern fails because the value does not match the pattern.

PATTERN_NOT_SET_MESSAGE_IDback to summary
public static final String PATTERN_NOT_SET_MESSAGE_ID

The message identifier of the javax.faces.application.FacesMessage to be created if the value returned from getPattern is null or the empty String.

regexback to summary
private String regex
transientValueback to summary
private boolean transientValue
VALIDATOR_IDback to summary
public static final String VALIDATOR_ID

The standard converter id for this converter.

Constructor Detail

RegexValidatorback to summary
public RegexValidator()

Method Detail

clearInitialStateback to summary
public void clearInitialState()

Implements javax.faces.component.PartialStateHolder.clearInitialState.

Doc from javax.faces.component.PartialStateHolder.clearInitialState.

Reset the PartialStateHolder to a non-delta tracking state.

Annotations
@Override
getPatternback to summary
public String getPattern()

Return the ValueExpression that yields the regular expression pattern when evaluated.

Returns:String

the pattern

initialStateMarkedback to summary
public boolean initialStateMarked()

Implements javax.faces.component.PartialStateHolder.initialStateMarked.

Doc from javax.faces.component.PartialStateHolder.initialStateMarked.

Return true if delta state changes are being tracked, otherwise false

Returns:boolean

true if the initial state is marked, false otherwise.

Annotations
@Override
isTransientback to summary
public boolean isTransient()

Implements javax.faces.component.StateHolder.isTransient.

Doc from javax.faces.component.StateHolder.isTransient.

If true, the Object implementing this interface must not participate in state saving or restoring.

Returns:boolean

true if transient, false otherwise.

Annotations
@Override
markInitialStateback to summary
public void markInitialState()

Implements javax.faces.component.PartialStateHolder.markInitialState.

Doc from javax.faces.component.PartialStateHolder.markInitialState.

The runtime must ensure that the markInitialState method is called on each instance of this interface in the view at the appropriate time to indicate the component is in its initial state. The implementor of the interface must ensure that initialStateMarked returns true from the time markInitialState() is called until clearInitialState is called, after which time initialStateMarked() must return false. Also, during the time that the instance returns true from initialStateMarked(), the implementation must return only the state that has changed in its implementation of StateHolder#saveState.

Annotations
@Override
restoreStateback to summary
public void restoreState(FacesContext context, Object state)

Implements javax.faces.component.StateHolder.restoreState.

Doc from javax.faces.component.StateHolder.restoreState.

Perform any processing required to restore the state from the entries in the state Object.

If the class that implements this interface has references to instances that also implement StateHolder (such as a UIComponent with event handlers, validators, etc.) this method must call the restoreState method on all those instances as well.

If the state argument is null, take no action and return.

Parameters
context:FacesContext

the Faces context.

state:Object

the state.

Annotations
@Override
saveStateback to summary
public Object saveState(FacesContext context)

Implements javax.faces.component.StateHolder.saveState.

Doc from javax.faces.component.StateHolder.saveState.

Gets the state of the instance as a Serializable Object.

If the class that implements this interface has references to instances that implement StateHolder (such as a UIComponent with event handlers, validators, etc.) this method must call the saveState method on all those instances as well. This method must not save the state of children and facets. That is done via the javax.faces.application.StateManager

This method must not alter the state of the implementing object. In other words, after executing this code:


Object state = component.saveState(facesContext);

component should be the same as before executing it.

The return from this method must be Serializable

Parameters
context:FacesContext

the Faces context.

Returns:Object

the saved state.

Annotations
@Override
setPatternback to summary
public void setPattern(String pattern)

The Regular Expression property to validate against.

Parameters
pattern:String

a regular expression pattern

setTransientback to summary
public void setTransient(boolean transientValue)

Implements javax.faces.component.StateHolder.setTransient.

Doc from javax.faces.component.StateHolder.setTransient.

Denotes whether or not the Object implementing this interface must or must not participate in state saving or restoring.

Parameters
transientValue:boolean

boolean pass true if this Object will not participate in state saving or restoring, otherwise pass false.

Annotations
@Override
validateback to summary
public void validate(FacesContext context, UIComponent component, Object value)

Implements javax.faces.validator.Validator.validate.

Validate a String against a regular expression pattern. The full regex pattern must be matched in order to pass the validation.

Parameters
context:FacesContext

Doc from javax.faces.validator.Validator.validate.

FacesContext for the request we are processing

component:UIComponent

Doc from javax.faces.validator.Validator.validate.

UIComponent we are checking for correctness

value:Object

Doc from javax.faces.validator.Validator.validate.

the value to validate

Annotations
@Override
Exceptions
NullPointerException:
if context or component is null
ValidatorException:
if validation fails