A formatter class provides formatting and validation functionality for the fields and inputs controlled by a Data Field Modifier builder call.
Formatter classes implement the com.bowstreet.methods.IInputFieldFormatter
interface and include code for the following aspects of formatting and validating form fields:
- Defines a list of expressions for formatting, translating, and validating inputs. These expressions describe a corresponding method that performs the operation and are used in the Data Field Modifier builder call to identify each of the methods in the formatter class.
- Implements format, translate, and validate methods.
- Implements utility methods to get and set error messages or get lists of expressions, for example.
The formatter takes raw phone number data (for example, 2075558487) and formats it to either a dot-separated format (for example, 207.555.8487) or a dash-separated (for example, (207)555-8487) format. It also makes sure that the user enters only numeric characters with its validate method.
You can implement any number of format, translation, or validation operations in a single formatter class.
The IInputFieldFormatter interface
As you begin development of your formatter class, implement the IInputFieldFormatter interface.
A format method implementation
The format method examines the expression it receives and calls the appropriate operation, passing the value as an argument to that operation.
Before adding the code that does the formatting, translating, and validating, you need to facilitate the creation of the various expression lists and some error message text.
A Translate Method Implementation
When the users enter a phone number, they may enter it without any separators or use some sort of separator such as dots or dashes.
A Validate Method Implementation
The validate method follows the process of analyzing an expression and calling the appropriate method to perform the actual operation; in this case validating that the user used only numeric characters for the phone number input.
Parent topic: Formatting and validating form values
WebSphere Portlet Factory API documentation