matthias
matthias

Reputation: 2062

Primefaces Calendar don't show seconds

I have a calendar where I can pick the date and time (only hours and minutes):

<p:calendar locale="de" pattern="dd.MM.yyyy HH:mm"

No I have to provide english translations as well. So I need to remove the locale and pattern part.

Is there a possiblility to have a locale aware calendar with date and time (no seconds) ?

Summary: When locale is German, I want to have dd.mm.yyyy HH:mm. When the locale is English, I want to have mm/dd/yyyy HH:mm

Upvotes: 1

Views: 1058

Answers (1)

Rung Ip
Rung Ip

Reputation: 91

Hook the pattern attribute up to a bean method which returns the pattern you want for each given locale.

<p:calendar pattern="#{bean.localePattern}">

public String getLocalePattern() {
    Locale locale = FacesContext.getCurrentInstance().getViewRoot().getLocale();
    if (Locale.GERMAN.equals(locale)) {
        return "dd.MM.yyyy HH:mm";
    } else if (Locale.ENGLISH.equals(locale)) {
        return "MM/dd/yyy HH:mm";
    }else {
        //return default pattern...
    }
}

Edit: Jaspers suggestion to take advantage of a localized resource bundle is a great one (if you're already/plan to use JSF's built in localization features).

Upvotes: 2

Related Questions