Saturday, March 20, 2010

ADF Faces RC: Change the Global Date Format of Your Application

To change the date format of your application, without necessarily affecting other locale settings like Language(localized text) ,or to established a standard global date format across different locales/countries, define the <formatting-locale> element of the trinidad-config.xml as illustrated below:
<?xml version="1.0" encoding="windows-1252"?>
<trinidad-config xmlns="http://myfaces.apache.org/trinidad/config">
  <formatting-locale>en-GB</formatting-locale>
</trinidad-config>
You can also define it with an EL that resolve to a java.util.Locale instead of a hard text (like en-GB)
<?xml version="1.0" encoding="windows-1252"?>
<trinidad-config xmlns="http://myfaces.apache.org/trinidad/config">
  <formatting-locale>#{userSession.formattingLocale}</formatting-locale>
</trinidad-config>
default (based on my browser's locale):

with formatting-locale set to "en-GB":

with formatting-locale set to "fr-CA":

with formatting-locale set to "ja":


Below is a quotation from section A.6.2.8 (Formatting Dates and Numbers Locale) of the Web User Interface Developer's Guide:
By default, ADF Faces and MyFaces Trinidad will format dates (including the first day of the week) and numbers in the same locale used for localized text (which by default is the locale of the browser). If, however, you want dates and numbers formatted in a different locale, you can use the element, which takes an IANA-formatted locale (for example, ja, fr-CA) as its value. The contents of this element can also be an EL expression pointing at an IANA string or a java.util.Locale object.
Two things that I have observed:
  1. The formatting-locale is case sensitive. For example, replacing "en-GB" with "en-gb" will NOT make localization work.
  2. When using EL, the expression should resolved to a java.util.Locale. An expression that resolves to a string like "en-GB" will throw an exception.

To learn how to bind configuration values to managed bean and/or how to configure general locale settings, please see the following post:
ADF Faces RC : Supplement on How to Configure Pages for an End User to Specify Locale at Runtime

Cheers!

6 comments:

  1. This is great but i have problem can you tell me
    How to use Hijri Data that are used in Arab countries
    i want to use Hijri date
    is this possible

    thanks in advance

    ReplyDelete
  2. Another thing I have observed is that the calendar popup labels (months, days, etc..) are changed to lang of the locale specified in . So this make this approach not usable.

    ReplyDelete
  3. Hi,
    You have a point. I'll try to dig more then.

    regards,

    Pino

    ReplyDelete
  4. www.parissys.org has solution for Hijri date in ADF 11g.

    for Hijri ADF Calendar look at the below file

    http://parsisys.org/fa/component/k2/item/4-%D8%AA%D9%82%D9%88%DB%8C%D9%85-%D9%87%D8%AC%D8%B1%DB%8C-%D8%B9%D8%B1%D8%A8%DB%8C-%D8%A8%D8%B1%D8%A7%DB%8C-adf.html

    also you can see a live demo on

    ReplyDelete
  5. Hi,

    I have one requirement in adf with dates can you please give some slotuion ti this tag.

    https://forums.oracle.com/forums/thread.jspa?messageID=10032223#10032223


    please give recent Date related question on this tag.

    ReplyDelete