Design Time Activities
cim1265
- ProblemDisplay an account expiration date in a user-friendly format based on separate month, day, and year fields. However, the date is stored in the database as a single physical attribute value in the format mm.dd.yyyy.
- SolutionCreate a logical attribute that associates the physical date attribute with three logical attributes that are displayed on the screen in separate Month, Day, and Year fields.
Although the date in this use case is an expiration date, the custom logical attribute handler is a general date handler that can process any type of date.
To create a logical attribute for handling expiration dates and other dates
- Register the new logical attribute handler in the Management Console:
- Create the logical attribute handler DateFormatAdapter by extending the class LogicalAttributeAdapter. The custom handler should implement the following methods:
- toLogical(). Converts the date physical attribute value to three separate logical attribute values.
- toPhysical(). Converts the three logical attribute values back to a single physical attribute value.
In this example, the attribute names you pass in are Month, Day, Year, and Date, as follows:
The handler uses the returned logical and physical attribute names when setting and retrieving attribute values.private final String LOGICAL_ATTRIBUTE_MONTH = "Month"; private final String LOGICAL_ATTRIBUTE_DAY = "Day"; private final String LOGICAL_ATTRIBUTE_YEAR = "Year"; private final String PHYSICAL_ATTRIBUTE_DATE = "Date"; . . . public void initialize(LogicalAttributeContext attrContext) throws Exception { String _month = attrContext.getLogicalAttributeName( LOGICAL_ATTRIBUTE_MONTH); String _day = attrContext.getLogicalAttributeName( LOGICAL_ATTRIBUTE_DAY); String _year = attrContext.getLogicalAttributeName( LOGICAL_ATTRIBUTE_YEAR); String _date = attrContext.getPhysicalAttributeName( PHYSICAL_ATTRIBUTE_DATE); . . . } - Deploy the compiled logical attribute handler DateFormatAdapter.
- Restart the environment.
- When creating the associated task screen in the User Console, assign the three logical attribute names to the Month, Day, and Year fields you add to the screen.It is not necessary to assign the corresponding physical attribute to a field on the task screen.