Working Around Bug 3958528 Where Date Format Truncates Time

Send me a mail
 Dive into Oracle ADF   Click to see the XML version of this web page.   (Updated: 2/3/2008; 9:25:50 PM.)
Tips and tricks from Steve Muench on Oracle ADF Framework and JDeveloper IDE

Working Around Bug 3958528 Where Date Format Truncates Time

Bug 3958528 reports a problem where the time portion of an oracle.jbo.domain.Date-valued attribute is truncated when it get formatted using the default date formatter.This note describes a workaround until we're able to include the fix in a maintenance release.

Observing the Problem

To observe the problem:

  1. Make sure some employee in your SCOTT account's EMP table has a time portion in its HIREDATE column value. For example, you might go into SQL*Plus and issue the command:
    UPDATE emp SET hiredate = SYSDATE WHERE empno = 7839;
    COMMIT;
  2. In JDeveloper, use the Business Components from Tables wizard to create a default entity object, view object, and appliation module for the SCOTT.EMP table.
  3. Visit the Entity Object editor for the Emp entity object, and expand the Attributes section to see the Hiredate attribute
  4. Click the Control Hints tab
  5. Select Simple Date for the Format Type
  6. Enter a format mask of MM/dd/yyyy HH:mm:ss
  7. Click (OK)
  8. Click on the application module and pick Test... from the right mouse menu

You'll see in the tester that the Hiredate attribute value shows a formatted time of 00:00:00 incorrectly.

Working Around the Problem

To workaround the problem, we'll create a custom date formatter which duplicates what the oracle.jbo.format.DefaultDateFormatter does, but which doesn't run into the problem above.

To workaround the problem:

  1. Create a new Java class named MyDefaultDateFormatter in any convenient package. For example, let's assume you call it, test.common.MyDefaultDateFormatter.
  2. Press [Ctrl]-[Minus] to "Goto Source" and type in the class name DefaultDateFormatter (the oracle.jbo.format package should be defaulted for you), and show the source code for it.

    NOTE: The source code for this class in included with JDeveloper in the ./BC4J/src/bc4jhtmlsrc.zip archive.
     
  3. Press [Ctrl]-A to copy the entire source of this file.
  4. In the editor buffer for MyDefaultDateFormatter, press [Ctrl]-A to select the entire file, then press [Ctrl]-V to paste the contents of DefaultDateFormatter in its place.
  5. Change the package name of this class back to test.common again.
  6. Search for DefaultDateFormatter and replace it to be named MyDefaultDateFormatter in the class name and the constructor method name.
  7. Add the line:
    import oracle.jbo.format.*;
    to the import section at the top of the file.
  8. Find the two places in the file where the call to the dateValue() method appears, and replace both of them with a call to timestampValue() instead.
  9. Compile the class.
  10. Visit the Emp entity object in the Entity Object editor again, and visit the panel for the Hiredate attribute.
  11. This time, click on the Attribute Properties tab
  12. In the Name field, enter the string (exactly as shown) value of FMT_FORMATTER
  13. In the Value field, enter the fully-qualified name of the custom formatter object test.common.MyDefaultDateFormatter
  14. Click (OK).

Now try repeating the test using the Business Components Tester tool, and you'll see that by using the custom date formatter object that fixed the calls to dateValue() to be calls to timestampValue() instead, you now correctly see the time portion of the date for the KING employee with EMPNO = 7839.

NOTE: If you deploy your ADF Business Components-based application in a physical three-tier architecture, the custom formatter classes need to be available both in the middle-tier environment and the remote client environment, so you should double-check that it gets included in both deployment profiles so it ends up in both MiddleTier and Common JAR files.



© Copyright 2008 Steve Muench. Click here to send an email to the editor of this weblog.
Last update: 2/3/2008; 9:25:50 PM.