0
votes

Updated : I have used primefaces calendar to show dates. It's default format is mm/dd/yy but for other locale like german it is dd.mm.yy. If I specify the format for english for example dd/MM/yyyy then it shows correct format for english but then on changing language to german it shows again dd/MM/yyyy instead of dd.MM.yyyy

I have tried this :

<p:calendar id="createdDateToDK"
    value="#{messagesDefaultKeys.createdDateTo}" showOn="button"
                mode="popup" navigator="true" pattern="dd/MM/yyyy>
                <f:converter converterId="messages.convertors.DateConvertor" />
</p:calendar>

I have tried below also:

<p:calendar id="createdDateToDK"
            value="#{messagesDefaultKeys.createdDateTo}" showOn="button"
            mode="popup" navigator="true">
            <f:convertDateTime for="createdDateToDK" pattern="dd/MM/yyyy"></f:convertDateTime>
</p:calendar>

I am using primefaces3.5 jar and JSF2.0 .

I do not want to add another calendar component just for another language . Please note that this happens only when I specify the format for calendar else while it works well with different locales.

1
there are a error in first example: on pattern="MM/dd/yyyy missing closing quote. I usualy use first example.Vasile Bors
what type is createdDateTo ? I see you use a convertorVasile Bors
Ah.... maybe a missing quote :( but now there is another problems same format is for all the locales for example for german it is same as english dd/MM/yyyy instead it should be dd.mm.yyyy createDateTo is of java.util.Date formatMohit Bhagat
try to send format as an EL expression from an bean fieldVasile Bors
using String pattern1 = ((SimpleDateFormat) DateFormat.getDateInstance(DateFormat.SHORT, locale)).toPattern(); you get the default date format for specified localeVasile Bors

1 Answers

0
votes

No need to use a converter for dates, calendar comes with an attribute called pattern, you can use it to change the pattern of dates, for exemple <p:calendar pattern="dd.MM.yyyy HH:mm" /> this will show 21.02.2017 15:42, you can change the pattern to separate the date however you like using dots, slach or any character