|
Version 3.10.0
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
public interface DateConverter
Convert text into a Date object, and Date objects into text.
See BuildImpl for important information on how this item is configured.
BuildImpl.forDateConverter()
returns the configured implementation of this interface.
The application programmer's implementation of this interface is used when WEB4J needs to
build a Date from user input, or format an existing Date object. Here is an
example implementation.
Using SimpleDateFormat is not recommended, since its
behavior when parsing items does not seem trustworthy, and it is not thread-safe.
Design Notes
Here are some forces concerning dates in Java web applications :
Date class is often used to model items which are different from the point of view
of the user : dates '01-31-2006', and date-times '01-31-2006 08:00:00'
SimpleDateFormat is mediocre, and perhaps even untrustworthy. It should be used with great care.
Locale is added to an application, then parsing and formatting of Date should not fail.
Instead, reasonable defaults should be defined for unknown Locales.
| Method Summary | |
|---|---|
String |
formatEyeFriendly(Date aDate,
Locale aLocale,
TimeZone aTimeZone)
Format a Date into an eye-friendly, legible format. |
Date |
parseEyeFriendly(String aInputValue,
Locale aLocale,
TimeZone aTimeZone)
Parse textual user input of an "eye-friendly" format into a Date object. |
Date |
parseHandFriendly(String aInputValue,
Locale aLocale,
TimeZone aTimeZone)
Parse textual user input of a "hand-friendly" format into a Date object. |
| Method Detail |
|---|
Date parseHandFriendly(String aInputValue,
Locale aLocale,
TimeZone aTimeZone)
Date object.
A hand-friendly format might be '01312006', while an eye-friendly format might be 'Jan 31, 2006'.
The implementation must return null when the user input cannot be
successfully parsed into a Date. It is recommended that the implementation
have reasonable default behaviour for unexpected Locales.
This method is called by RequestParser.
aInputValue - user input value, as returned by ConvertParam.filter(String)
(always has content).aLocale - is obtained from the configured LocaleSource, and passed to this method
by the framework.aTimeZone - is obtained from the configured TimeZoneSource, and passed to this method
by the framework.
Date parseEyeFriendly(String aInputValue,
Locale aLocale,
TimeZone aTimeZone)
Date object.
A hand-friendly format might be '01312006', while an eye-friendly format might be 'Jan 31, 2006'.
The implementation must return null when the user input cannot be
successfully parsed into a Date. It is recommended that the implementation
have reasonable default behaviour for unexpected Locales.
This method is called by RequestParser.
aInputValue - user input value, as returned by ConvertParam.filter(String)
(always has content).aLocale - is obtained from the configured LocaleSource, and passed to this method
by the framework.aTimeZone - is obtained from the configured TimeZoneSource, and passed to this method
by the framework.
String formatEyeFriendly(Date aDate,
Locale aLocale,
TimeZone aTimeZone)
Date into an eye-friendly, legible format.
The implementation must return an empty String when the Date is null.
It is recommended that the implementation have reasonable default behaviour for unexpected Locales.
The framework will call this method when presenting listings using
Report, and when presenting a Model Object in a form
for a "change" operation.
This method is called by Formats.
aDate - to be presented to the user in a legible formataLocale - is obtained from the configured LocaleSource, and passed to this method
by the framework.aTimeZone - is obtained from the configured TimeZoneSource, and passed to this method
by the framework.
parseEyeFriendly(String, Locale, TimeZone)
|
Version 3.10.0
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||