|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.fedmest.cw.keyboard.validators.DateValidator
public final class DateValidator
This class parses a string from user input. Create this class by specifying either a format string following the conventions of
the SimpleDateFormat class or by passing an actual instance of a DateFormat into the constructor. You can then use
your validator instance with the KeyboardUtils class to get a date from the user. If the user canceled input on a cancelable
KeyboardUtils, the class will return null instead of a Date.
| Constructor Summary | |
|---|---|
DateValidator(java.text.DateFormat format)
Creates a new instance of this validator with a DateFormat instance detailing how the date should be parsed from the
typed string. |
|
DateValidator(java.lang.String formatString)
Creates a new instance of this validator with a string that represent the accepted format of the date that will be parsed following the conventions of the SimpleDateFormat class. |
|
| Method Summary | |
|---|---|
java.util.Date |
cancelValue()
Allows you to specify the return value to offer when the user cancels input on a cancelable instance of KeyboardUtils
. |
java.util.Date |
checkInput(java.lang.String txt)
Takes the input string, checks its validity and converts it to the data type specified by the type argument. |
void |
resetErrorMessage()
This method resets the error message that will be displayed to users on validation failure to the default text ("Invalid date - retry"). |
void |
resetMax()
This method resets the latest date that will be accepted by this validator to the latest possible date value. |
void |
resetMin()
This method resets the earliest date that will be accepted by this validator to the earliest possible date value. |
void |
resetRange()
This method resets the earliest and latest dates that will be accepted by this validator to the earliest and latest possible date values respectively. |
void |
resetRangeMessage()
This method resets to the default text the error message that will be displayed to users when the value is out of range ("Value out of range - retry"). |
void |
setErrorMessage(java.lang.String errorMessage)
Sets the error message that will be displayed to the user if validation fails because the input string was not a proper date value. |
void |
setMax(java.util.Date max)
This method sets the latest date that will be accepted by this validator. |
void |
setMin(java.util.Date min)
This method sets the earliest date that will be accepted by this validator. |
void |
setRange(java.util.Date min,
java.util.Date max)
This method sets the earliest and latest dates that will be accepted by this validator. |
void |
setRangeMessage(java.lang.String rangeMessage)
This method sets the error message that will be displayed to the user if validation fails due to a value being outside of the range specified with setMax(Date), setMin(Date) or setRange(Date, Date). |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public DateValidator(java.lang.String formatString)
SimpleDateFormat class.
formatString - the format specification of the date to parsepublic DateValidator(java.text.DateFormat format)
DateFormat instance detailing how the date should be parsed from the
typed string.
format - an instance of the DateFormat class used for date parsing| Method Detail |
|---|
public void resetErrorMessage()
setErrorMessage(String)public void setErrorMessage(java.lang.String errorMessage)
DateFormat.parse(String), invoked internally by this validator, raises a
ParseException.
errorMessage - the new error messages to display to users when validation fails for any reason.resetErrorMessage()public void setRangeMessage(java.lang.String rangeMessage)
setMax(Date), setMin(Date) or setRange(Date, Date).
rangeMessage - the new error message to display to userspublic void resetRangeMessage()
setRangeMessage(String)public void setMax(java.util.Date max)
max parameter.
max - the latest date allowed in parsing (inclusive)public void resetMax()
setMax(Date)public void setMin(java.util.Date min)
min parameter.
min - the earliest date allowed in parsing (inclusive)public void resetMin()
setMin(Date)
public void setRange(java.util.Date min,
java.util.Date max)
min and max parameters.
Invoking this method is equivalent to invoking setMin(Date) and setMax(Date).
min - the earliest date allowed in parsing (inclusive)max - the latest date allowed in parsing (inclusive)setMin(Date),
setMax(Date)public void resetRange()
setMin(Date),
setMax(Date),
resetMin(),
resetMax()
public java.util.Date checkInput(java.lang.String txt)
throws KeyboardInputException
KeyboardInputValidatorKeyboardInputException is raised and the user will have to type their input again. If a null
reference is passed into the method, the method may throw a NullPointerException, so programmers do not need to worry
about checking for null pointers.
checkInput in interface KeyboardInputValidator<java.util.Date>txt - the input text. If the string is null, NullPointerException will be thrown.
KeyboardInputException - if validation against the input string failedpublic java.util.Date cancelValue()
KeyboardInputValidatorKeyboardUtils
. Though null should be returned in most cases, this method is useful when - for example - you want to return a
primitive type from your validator and can't use null as a return value without causing a bit of inconvenienve in
your application code (explicit unboxing and checks for null values).
cancelValue in interface KeyboardInputValidator<java.util.Date>
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||