Version 3.10.0

hirondelle.web4j.request
Interface DateConverter


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 :


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

parseHandFriendly

Date parseHandFriendly(String aInputValue,
                       Locale aLocale,
                       TimeZone aTimeZone)
Parse textual user input of a "hand-friendly" format into a 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.

Parameters:
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.

parseEyeFriendly

Date parseEyeFriendly(String aInputValue,
                      Locale aLocale,
                      TimeZone aTimeZone)
Parse textual user input of an "eye-friendly" format into a 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.

Parameters:
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.

formatEyeFriendly

String formatEyeFriendly(Date aDate,
                         Locale aLocale,
                         TimeZone aTimeZone)
Format a 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.

Parameters:
aDate - to be presented to the user in a legible format
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.
Returns:
text compatible with parseEyeFriendly(String, Locale, TimeZone)

Version 3.10.0

Copyright Hirondelle Systems. Published September 20, 2008 - User Guide - All Docs.