4GL Patterns #4 - Type Converter Pattern
Wednesday, 17 September 2008
Database types which have a text representation include Currency, Date/Time, Boolean fields. If these fields are presented in text boxes, then appropriate formatters and parsers are used to translate text into actual model values and vice versa.
There are two types of parsers:
- strict where field masks are provided to ensure the user typed in data in a fixed format, e.g. dd/mm/yyyy
- humane where free text is parsed. Some libraries provide parse English-like phrases such as “next Friday” into date and time.
Examples
JSF Type Converters
A more interesting example is how Excel handles this. A currency value is formatted with 2 decimal places, but the underlying value happens to be significant up to 4 decimal places. When the cell is being edited, the currency sign is removed and all the significant digits appear so that the user may edit it. Here is a screenshot:
If you find this post interesting, leave a comment, or explore other 4GL tags below.
