Tuesday, October 28, 2014

Handling Date Format and ADF Bindings

There are tips and tricks related to the date format handling and ADF bindings. When Oracle date type attribute is being used through ADF binding expression, it will be converted to String with default format (yyyy-MM-dd), no matter what original format was set. This is described in API for the Oracle date type - Date constructor with String. Below I'm going to explain how it works and how you could optimise ADF application to handle date type attributes from ADF bindings layer.

Sample application (download it here - DateFormatApp.zip) is based on one simple VO with calculated attributes, both oracle.jbo.domain.Date type:

ADF UI implementation is standard - there are ADF Input Date components with regular date converters:

There is a button on UI, it calls custom method implemented in VO and exposed through the bindings. This method accepts two parameters, both oracle.jbo.domain.Date type. I'm using regular binding expression and getting inputValue property (this returns formatted value of the date):

Try to invoke the method, you will get an error about invalid argument - binding expression with date attribute is not accepted. It is trying to use formatted value dd/MM/yyyy and set it for the custom method argument value, but Oracle date accepts only yyyy-MM-dd (I'm using Alta UI skin):

Error message is written in the log:

The workaround is to use attributeValue instead of inputValue in the binding expression. Property attributeValue returns original unformatted date type attribute value:

Do the same test again, type both dates and press Test Dates button - this would work now:

I'm checking out date values in the custom method. Originally it comes unformatted date value, taken from attributeValue property. If we would like to use date value in the certain format (e.g. send to PL/SQL in format dd/MM/yyyy, instead of default yyyy-MM-dd), we should apply DefaultDateFormatter to retrieve the formatted String value for the original date:

Here is the output from the custom method:


luckyservant said...

Hi Andrejus,
That is what i'm looking for, thanks so much. A tiny correction: "it calls custom method implemented in AM" as far as i see method is implemented in VO


Ümit Sadegüzel

Andrejus Baranovskis said...

Thanks, I have fixed typo.