Ronald
Ronald

Reputation: 299

Primefaces Calendar set Locale

I am working with PrimeFaces Calendar component and want to set the Locale, I am using Primefaces 5.2, JSF 2.2 my code is :

principal.xhtml

<h:head>
        <link rel="shortcut icon" type="image/x-icon" href="/resources/images/logoconsorcio.ico"/>
        <f:facet name="first">
            <h:outputStylesheet name="css/default.css"/>
            <h:outputScript name="js/scripts.js" />
            <h:outputScript library="js" name="calendar_es.js" />
            <title>Consorcio JM</title>
        </f:facet>
</h:head>
<h:body>
        <p:layout fullPage="true">
        </p:layout>
    ....    
</h:body> 

calendar_es.js is set in the resources folder in the web root

PrimeFaces.locales['es'] = {
closeText: 'Cerrar',
prevText: 'Anterior',
nextText: 'Siguiente',
monthNames: ['Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'],
monthNamesShort: ['Ene', 'Feb', 'Mar', 'Abr', 'May', 'Jun', 'Jul', 'Ago', 'Sep', 'Oct', 'Nov', 'Dic'],
dayNames: ['Domingo', 'Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes', 'Sábado'],
dayNamesShort: ['Dom', 'Lun', 'Mar', 'Mie', 'Jue', 'Vie', 'Sab'],
dayNamesMin: ['D', 'L', 'M', 'Mi', 'J', 'V', 'S'],
weekHeader: 'Semana',
firstDay: 1,
isRTL: false,
showMonthAfterYear: false,
yearSuffix: '',
timeOnlyTitle: 'Sólo hora',
timeText: 'Tiempo',
hourText: 'Hora',
minuteText: 'Minuto',
secondText: 'Segundo',
currentText: 'Fecha actual',
ampm: false,
month: 'Mes',
week: 'Semana',
day: 'Día',
allDayText: 'Todo el día'
};

and my snippet of calendar is :

<p:calendar showOn="button" pattern="dd/MM/yyyy" value="#{comprobanteBean.cpVista.fecha}"
                styleClass="dateTimeFieldRP" required="true" mask="true" locale="es"/>

but it isn't working, so the calendar is in English.

Thanks for all.

Upvotes: 2

Views: 7562

Answers (1)

Oscar P&#233;rez
Oscar P&#233;rez

Reputation: 4397

This is an old question, but recently I faced the same problem. In my case, the javascript PrimeFaces.locales['es'] = {...} was inside a JQuery ready event.

I had to move it out of this event, as it was processed after my components initialization.

Upvotes: 3

Related Questions