fieldformatting
Class DateFieldHandler

java.lang.Object
  extended by com.wrq.vhi.script.api.FieldEventHandler
      extended by fieldformatting.DateFieldHandler
All Implemented Interfaces:
com.wrq.vhi.script.api.EventHandler

public class DateFieldHandler
extends com.wrq.vhi.script.api.FieldEventHandler

This example illustrates how to use an event handler to read and reformat a recordset field before it is sent to the client application. This is done by:

  1. Using the defaultReadField method provided by the event object to read the field as it is displayed by the host application, and
  2. Sending the field value to a method in a DateFormatter instance to reformat the date into the desired form.

The source code for the DateFormatter class is stored in the shared examples directory. The Jar file containing the class is copied into this example's lib directory by the ant build file.

What's different about this example is that the date formatter instance is created as a static variable within this class. When this class is loaded, the formatter static variable is created. The initialization parameters for the formatter tell it the host date syntax, and the era within which two-digit years are assumed to fall.

If you wanted to handle other two-digit dates with different separator characters, or within a different era, you would define a different attribute (or field) handler which would create a different DateFormatter instance initialized to handle that other kind of date.

When you look at the source code for the DateFormatter class, notice that the instance variables are all defined as final. This means that the only data changed by that class's methods are either parameters or local to each method; the methods are thread-safe.


Field Summary
static java.lang.String description
           
private static DateFormatter formatter
          Instance of date formatter used to reformat dates in this application.
static int readFieldTimeout
          Timeout in seconds for the readField() event.
static int writeFieldTimeout
          Timeout in seconds for the writeField() event.
 
Fields inherited from interface com.wrq.vhi.script.api.EventHandler
DEFAULT_TIMEOUT
 
Constructor Summary
DateFieldHandler()
           
 
Method Summary
 java.lang.String readField(com.wrq.vhi.script.api.ReadFieldEvent event)
          Read a date-formatted recordset field and convert to standard form.
 
Methods inherited from class com.wrq.vhi.script.api.FieldEventHandler
writeField
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

description

public static final java.lang.String description
See Also:
Constant Field Values

formatter

private static final DateFormatter formatter
Instance of date formatter used to reformat dates in this application.

The first two-digit year is assumed to be 1970.

The month, day, and year in the host application display are separated by a hyphen character.


readFieldTimeout

public static final int readFieldTimeout
Timeout in seconds for the readField() event. A value of DEFAULT_TIMEOUT means the event will use the model defined default event timeout.

See Also:
Constant Field Values

writeFieldTimeout

public static final int writeFieldTimeout
Timeout in seconds for the writeField() event. A value of DEFAULT_TIMEOUT means the event will use the model defined default event timeout.

See Also:
Constant Field Values
Constructor Detail

DateFieldHandler

public DateFieldHandler()
Method Detail

readField

public java.lang.String readField(com.wrq.vhi.script.api.ReadFieldEvent event)
                           throws com.wrq.apptrieve.agent.ApptrieveException
Read a date-formatted recordset field and convert to standard form.

A check is made for an empty (blank) field. The "default read" for fields in this recordset will remove leading and trailing blanks. Further, this recordset will read a single blank record to terminate the fetch on the last screen of the recordset. This event handler must treat that as a special case: the date formatter will not accept a blank string as a valid date.

Overrides:
readField in class com.wrq.vhi.script.api.FieldEventHandler
Parameters:
event - the event instance
Returns:
the field value
Throws:
com.wrq.apptrieve.agent.ApptrieveException