Portlet Factory, Version 6.1.2


 

Formatting and validation of individual fields

The Data Field Modifier builder supports using arguments with the methods on the Formatter class. The following sections describe the formatting and validation considerations.

 

The standard formatter class

If you add to your model a Data Field Modifier builder that refers to a field that is not a container, you can apply formatting to the field. The builder inputs used to apply the formatting are in the Formatting group. Specify in the Formatter Class input the class to use. The following StandardFormatter class is supplied in IBM® WebSphere Portlet Factory to get you started.

com.bowstreet.builders.webapp.pageautomation.StandardFormatter

The class contains several formatting methods that you can use. When you specify a class, the Format Expression, Translate Expression, and the Validate Expression inputs are populated with the available methods provided by the class.

 

Format Expression input

The Format Expression input is populated with the methods to format the data but retain the original values. For example, given a Date Time of 05/19/2004 12:14:22, if Date Only is selected, 05/19/2004 is displayed on the page. However, the variable continues to hold the full value of 05/19/2004 12:14:22.

If the field being formatted is a String and you select DateTimeFormat(FormatString) for the Format Expression input, the method attempts to parse the String into a Date Time. It uses the format of the String to determine how to display the Date Time by default. For example, if the String is 05/19/2004 12:14:22, the string is displayed in that format. However, you can integrate a Date / Time Formatter builder and specify how Date Times should be displayed and therefore specify how this String gets formatted.

If you select an expression that contains parentheses (), you can specify the format of the arguments in the Format Exp Argument input. For more information, see Formatting with methods that take arguments.

 

Custom date formatting options

Date formats can be specified on a model wide basis or on a field by field basis. Properties that control format behavior must be added to the override.properties file. You can change the values of the properties to deal with your specific formats.

There are two properties that apply to date formats, two that apply to dateTime formats, and two that apply to time formats. Each property set consists of a property for data and a property for display.

Note: To activate these properties, add them to the override.properties file and restart the application or portal server.

The date properties

# Set the format string for the data value of dates
# bowstreet.pageautomation.date.data=MM/dd/yyyy

# Set the format string for the display of dates# bowstreet.pageautomation.date.display=MMMM dd, yyyy

The first property is used to parse your date strings. Thus all of your dates should be in this format to start with. The second property represents the format to use to display dates. In the example above, dates should look like 07/04/2004 before parsing. Once formatted, they look like July 04, 2004.

The date/time properties

# Set the format string for the data value of dateTimes
# bowstreet.pageautomation.dateTime.data=MM/dd/yyyy hh:mm:ss

# Set the format string for the display of dateTimes
# bowstreet.pageautomation.dateTime.display=long

The time properties

# Set the format string for the data value of times
# bowstreet.pageautomation.time.data=hh:mm:ss

# Set the format string for the display of times
# bowstreet.pageautomation.time.display=hh:mm

To specify formats by individual element, add a Data Field Modifier builder. Select the date element to format. In the Formatter Class input, select the standard formatter class to use for formatting methods. Select the Format(Data$Display) choice as the method for the Format Expression input. Supply an argument to specify the formats for this particular date. The argument should be entered in the Format Exp Argument input and should take the form of Data$Display. For example, specify dd/MM/yyyy$MM-dd-yyyy if your date is in the form of 04/07/2004 and it is to be displayed as 07-04-2004.

If your dates are stored as long words, you can specify this format too. Do one of the following:

  • In the override.properties file, use the following entry.
    bowstreet.pageautomation.date.data=long

  • In the Data Field Modifier builder, use long$DisplayFormat. Use DisplayFormat to display the date.

 

Translate Expression input

The Translate Expression input is populated with the methods to actually change (translate) the value in the variable rather than changing only what is displayed. For example, use the DateTime selection to explicitly translate from one date format to a format that includes both the calendar month, day, year and time of day.

If you select an expression that contains parentheses (), you can specify the format of the arguments in the Translate Exp Argument input. For more information, see Formatting with methods that take arguments.

 

Validate Expression input

The Validate Expression input is populated with the methods to ensure that the data is in the correct format. Using one of the required methods causes validation to be applied to the field for the specified type. For example, Required Date Time ensures that a value is entered by the user for this field and that the value entered is in fact a Date Time. Anything else including a Date fails the validation and causes an error to be displayed on the page.

Use one of the optional methods to allow a data entry field to be left blank and yet still validate correctly. For example, you can select Optional Date Time to force a field to validate a date and time entry or allow the field to be left blank.

If you select an expression that contains parentheses (), you can specify the format of the arguments in the Validate Exp Argument input. For more information, see Formatting with methods that take arguments. If no format is specified in the Data Field Modifier builder, the bowstreet.pageautomation.dateinput property is used if it is set.

 

Formatting with methods that take arguments

The inputs in the Formatting section of the Data Field Modifier builder support using arguments. If a method in the class that you specify in the Formatter Class input has parentheses (), it can take arguments. If the method takes arguments, you need to specify the format of the arguments. If you select an expression that includes parentheses, the builder displays one of the following inputs in which you specify the argument format.

  • Format Exp Argument

  • Translate Exp Argument

  • Validate Exp Argument
The formats can be indirect values (and are selected with the appropriate picker). (These strings are identical to those used in the Java NumberFormat and DateFormat classes.)

In the StandardFormatter, a validation operation is available.

RegularExpression(RegExString)

The Validate Exp Argument input is available. Enter a RegEx expression to be used for field validation. RegEx expressions are available to support a wide variety of operations. Click http://www.regexlib.com/ to access a library of these expressions and examples of their use.

If you supply your own formatter class, you can use the same convention to indicate arguments to be passed to the method used.

Parent topic: Data Field Modifier builder


Library | Support |