Thursday, May 15, 2014

Implementing Dynamic Date Type Formatting with ADF BC

You may have a requirement to apply different format for date type attributes, based on username, as for example. Different users, may use different date formats - in such case, formatting for date type attributes must be set dynamically. This can be achieved, using approach described in my previous post - Controlling ADF BC Mandatory Attribute Validation Conditionally. I would extend explained technique and apply it for date formatting.

Sample application for download - DynamicFormatADFApp.zip. Here you can see two different browser sessions, two different users and different date formats applied in both cases. dd/MM/yyyy is applied for redsam1 and yyyy/MM/dd for redsam2:


ADF UI is standard for a inputDate component in a form - format is set through a standard EL expression in convertDateTime tag by referencing format property from AttributeDef object:


EL expression to get a format for the attribute, rendered in ADF table is changed slightly (otherwise, with default EL expression, overridden getFormat method is not invoked):


Generic View Row Implementation class must override createViewRowAttrHints and getAttributeHints methods - this would allow pass a custom format to be applied on ADF UI dynamically:


Finally CustomViewRowAttrHintsImpl class overrides framework method getFormat (this method is invoked from ADF UI EL for format property automatically). Here we could check for a username and return dynamic format (in real use case, this logic can be more complex):

3 comments:

Anonymous said...

Hello Andrejus,

Great Post.!!

We have use case where I need to pass additional information for each VO attribute from AMImpl to UI(jspx/jsff)
For example,
EmployeeVO
-FirsName
-LastName
-Email
-PhoneNumber

While rendering in UI, for each of these attributes, I need to pass status information(which is not persisted in database. Its calculated information based on some functionality)

The intention is to pass additional information for each row and each attribute.

Is there a way to pass this additional information from AMImpl to UI?

Thank you in advance.

Andrej Baranovskij said...

Hi,

I believe this post may help you with some ideas: http://andrejusb.blogspot.com/2014/01/accessing-custom-attribute-property.html

Regards,
Andrejus

Anonymous said...

Hi,

How to change dateformat in ADF GUI 12.2.1? I want to change from MM/dd/yyyy to MM/dd/yyyy HH:mm:ss dynamically.