org.apache.cocoon.faces.samples.carstore
Class FormatValidator

java.lang.Object
  extended by org.apache.cocoon.faces.samples.carstore.FormatValidator
All Implemented Interfaces:
EventListener, javax.faces.component.StateHolder, javax.faces.validator.Validator

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

FormatValidator is a Validator that checks the validity of String representation of the value of the associated component against a list of specified patterns.

Validators have to be Serializable, so you can't maintain a reference to a java.sql.Connection or javax.sql.DataSource inside this class in case you need to hook upto the database or some other back end resource. One approach would be to use JNDI-based data source lookups or do this verification in the business tier.


Field Summary
static String FORMAT_INVALID_MESSAGE_ID
          The message identifier of the Message to be created if the validation fails.
 
Fields inherited from interface javax.faces.validator.Validator
NOT_IN_RANGE_MESSAGE_ID
 
Constructor Summary
FormatValidator()
           
FormatValidator(String formatPatterns)
          Construct a FormatValidator with the specified formatPatterns String.
 
Method Summary
 String getFormatPatterns()
          Return the format patterns that the validator supports.
protected  boolean isFormatValid(String pattern, String value)
          Returns true if the value matches one of the valid patterns.
 boolean isTransient()
           
 void parseFormatPatterns()
          Parses the formatPatterns into validPatterns ArrayList.
 void restoreState(javax.faces.context.FacesContext context, Object state)
           
 Object saveState(javax.faces.context.FacesContext context)
           
 void setFormatPatterns(String formatPatterns)
          Set the format patterns that the validator support..
 void setTransient(boolean transientValue)
           
 void validate(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component, Object toValidate)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FORMAT_INVALID_MESSAGE_ID

public static final String FORMAT_INVALID_MESSAGE_ID

The message identifier of the Message to be created if the validation fails. The message format string for this message may optionally include a {0} placeholder, which will be replaced by list of format patterns.

See Also:
Constant Field Values
Constructor Detail

FormatValidator

public FormatValidator()

FormatValidator

public FormatValidator(String formatPatterns)

Construct a FormatValidator with the specified formatPatterns String.

Parameters:
formatPatterns - | separated String of format patterns that this validator must match against.
Method Detail

getFormatPatterns

public String getFormatPatterns()

Return the format patterns that the validator supports.


setFormatPatterns

public void setFormatPatterns(String formatPatterns)

Set the format patterns that the validator support..

Parameters:
formatPatterns - | separated String of format patterns that this validator must match against.

parseFormatPatterns

public void parseFormatPatterns()
Parses the formatPatterns into validPatterns ArrayList. The delimiter must be "|".


validate

public void validate(javax.faces.context.FacesContext context,
                     javax.faces.component.UIComponent component,
                     Object toValidate)
Specified by:
validate in interface javax.faces.validator.Validator

isFormatValid

protected boolean isFormatValid(String pattern,
                                String value)
Returns true if the value matches one of the valid patterns.


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

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


Copyright © 1999-2010 The Apache Software Foundation. All Rights Reserved.