Date Format <formatting-locale> in ADF changes language in input-date as well with Date format in DD-MM-YY in JAVA

Viewed 284

I need to change the date format with DD-MM-YY for English language for country India. But I am unable to get locale for DD-MM-YY in English language in trinidad-config.xml. I have tried with other region for achieving the date format. But it changes the language for input date in ADF.

<formatting-locale>da-DK</formatting-locale>

But I want only date format to be change not the language. The language should remain English.

in faces-config.xml,

<default-config>en</<default-config>

But this also does not help.

Even I have a filter class and tried to achieve the language to be changed back to English.

Locale.setDefault(Locale.ENGLISH);

On printing the locale in the console, it shows en-US (if not programmatically) and en (if programmatically above code is set).

But its also not affecting the input date.

1 Answers

I do not know anything about Oracle ADF. But I can show that automatic localisation of the java.time does work.

Localization

LocalDate is the type to use to represent a date-only value, without time-of-day and without time zone.

To get a Locale, specify a human language to use in translation. For example, en for English or hi for Hindi. And specify a country for cultural norms to be used in formatting, capitalization, abbreviation, and such. For example, IN for India and UK for United Kingdom.

LocalDate.now(                        // Get today’s date…
    ZoneId.of( "Asia/Kolkata" )       // …as seen in this particular time zone.
)                                     // Return a `LocalDate` object.
.format(                              // Generate text to represent the value within that `LocalDate` object.
    DateTimeFormatter
    .ofLocalizedDate(                 // Ask java.time to automatically localize.
        FormatStyle.FULL              // How long or abbreviated do you want your text.
    )                                 // Returns a `DateTimeFormatter` object used to generate text.
    .withLocale (
        new Locale( "hi" , "India" )  // Hindi language, India cultural norms.
    )                                 // Returns a second `DateTimeFormatter` object, per immutable objects pattern. 
)                                     // Returns a `String` object.

See this code run live at IdeOne.com

शनिवार, 28 नवंबर 2020

Setting default locale

I suggest you avoid setting the default locale. That call immediately affects all code in all threads of all apps running within that JVM. Ditto for default time zone, by the way.

Pass the desired locale as an object argument to the appropriate methods.

Related