• Settings
    • Locale
    • Change the locale of the datepicker, schedule and client side validation messages.

      Language
      English
      English
      English
      French
      German
      German
      German
      Italian
      Korean
      Spanish
      Catalan
      Dutch
      Portuguese
      Portuguese
      Arabic
      Arabic
      Bulgarian
      Bangla
      Bosnian
      Czech
      Greek
      Estonian
      Persian
      Finnish
      Danish
      Hindi
      Indonesian
      Icelandic
      Croatian
      Japanese
      Hungarian
      Hebrew
      Georgian
      Central Kurdish
      Khmer
      Kyrgyz
      Kazakh
      Lithuanian
      Latvian
      Malay
      Norwegian
      Polish
      Romanian
      Russian
      Slovak
      Slovenian
      Serbian
      Serbian
      Swedish
      Thai
      Turkish
      Ukrainian
      Uzbek
      Vietnamese
      Chinese
      Chinese
  • Resources

TimePicker

TimePicker is a highly configurable component to integrate time inputs (hours / minutes) in a convenient way. A typical area of application is working time registration, expense and travel accounts. See the Internationalisation page for how to localize the component in multi-language applications.

TimePicker Tag Documentation

TimePicker is a time selection input with popup, spinner or inline mode.

NameTypeRequiredDefaultDescription
id String false generated Unique identifier of the component in a namingContainer.
rendered boolean false true Boolean value to specify the rendering of the component, when set to false component will not be rendered.
binding UIComponent false generated An EL expression referring to a server side UIComponent instance in a backing bean.
widgetVar String false generated ('widget_' + componentClientId) Name of the client side widget.
accesskey String false Access key to transfer focus to the input element.
alt String false Alternate textual description of the input field.
ariaDescribedBy String false Identifies the element(s) that describe the object, enhancing accessibility.
ariaLabelledBy String false
autocomplete String false Controls browser autocomplete behavior. Possible values are 'on', 'off', and 'new-password'.
converter Converter false EL expression resolves to a converter instance or literal converter ID defining a component converter.
converterMessage String false Custom message to display when conversion fails.
dialogPosition String false left top Position of the dialog.
dir String false ltr Direction indication for text that does not inherit directionality.
disabled boolean false false Specifies that an element should be disabled.
endHours int false 23 Last hour in range.
endMinutes int false 55 Last minute in range.
immediate boolean false false When set true, process validations logic is executed at apply request values phase for this component.
inputPosition String false left bottom Position of the input relative to dialog.
inputmode String false Specifies the type of data expected in the input, aiding virtual keyboards.
intervalMinutes int false 5 Minute step interval.
label String false A localized user presentable name.
lang String false Specifies the language of the element's content.
localValueSet boolean false false Indicates whether the local value of the component has been set.
locale Object false Locale for formatting (string or Locale).
maxHour Integer false Maximum hour.
maxMinute Integer false Maximum minute.
maxlength int false Integer.MIN_VALUE Defines the maximum number of characters allowed in the input.
minHour Integer false Minimum hour.
minMinute Integer false Minimum minute.
mode String false spinner Display mode: popup, spinner, or inline.
onHourShow String false Client-side callback when hour list is shown.
onMinuteShow String false Client-side callback when minute list is shown.
onblur String false Fires when an element loses focus.
onchange String false Fires when the value of an element has been changed.
onclick String false Fires when a mouse click on the element.
oncontextmenu String false Script to execute when the context menu is triggered.
oncopy String false Script to execute when content is copied from the element.
oncut String false Script to execute when content is cut from the element.
ondblclick String false Fires when a mouse double-click on the element.
ondrag String false Script to execute when an element is dragged.
ondragend String false Script to execute at the end of a drag operation.
ondragenter String false Script to execute when a dragged element enters a valid drop target.
ondragleave String false Script to execute when a dragged element leaves a valid drop target.
ondragover String false Script to execute when a dragged element is over a valid drop target.
ondragstart String false Script to execute at the start of a drag operation.
ondrop String false Script to execute when a dragged element is dropped.
onfocus String false Fires when an element gets focus.
oninput String false Script to execute when the element receives user input.
oninvalid String false Script to execute when the element's value is invalid.
onkeydown String false Fires when a user is pressing a key.
onkeypress String false Fires when a user presses a key.
onkeyup String false Fires when a user releases a key.
onmousedown String false Fires when a mouse button is pressed down on an element.
onmousemove String false Fires when the mouse pointer is moving while it is over an element.
onmouseout String false Fires when the mouse pointer moves out of an element.
onmouseover String false Fires when the mouse pointer moves onto an element.
onmouseup String false Fires when a mouse button is released over an element.
onpaste String false Script to execute when content is pasted into the element.
onreset String false Script to execute when the form is reset.
onscroll String false Script to execute when the element is scrolled.
onsearch String false Script to execute when a search is performed.
onselect String false Script to execute when text is selected.
onwheel String false Script to execute when the mouse wheel is used.
placeholder String false Specifies a short hint describing the expected value of the input.
readonly boolean false false Specifies that an input field is read-only.
readonlyInput boolean false false Input is read-only.
required boolean false false Marks component as required.
requiredMessage String false Custom message to display when the required validation fails.
role String false Defines the role of the element for accessibility purposes.
rows int false 4 Number of rows in dropdown.
showCloseButton boolean false false Show close button.
showDeselectButton boolean false false Show deselect button.
showHours boolean false true Show hours column.
showMinutes boolean false true Show minutes column.
showNowButton boolean false false Show now button.
showOn String false focus When to show picker: focus or button.
showPeriod boolean false false Use 12-hour AM/PM period.
size int false 5 Size of the input field.
startHours int false 0 First hour in range.
startMinutes int false 0 First minute in range.
style String false Specifies an inline CSS style for an element.
styleClass String false Specifies one or more CSS class names for an element.
submittedValue Object false
tabindex String false Specifies the tab order of an element.
timeSeparator String false : Separator between hours and minutes.
title String false Specifies extra information about an element (displayed as a tooltip).
type String false text Input field type.
valid boolean false true Indicates whether the input's value is valid.
validator Validator false A method expression referring to a method validating the input.
validatorMessage String false Custom message to display when validation fails.
value Object false Value of the component.
valueChangeListener ValueChangeListener false A method binding expression referring to a method for handling a valuchangeevent.
Tag Documentation Widget Source
Basic usage and three modes

Time picker has three modes: inline, popup and spinner. The spinner is the most convenient because it increments / decrements hours and minutes, but it is not compatible with onHourShow / onMinuteShow. The customized picker sets the time separator, start / end hours and minutes, the minute interval, buttons and more.

Inline mode

Popup mode

Spinner mode

Customization

Show popup by button

Spinner with button

Advanced usage, events and callbacks

AJAX events timeSelect, beforeShow and close, hours-only and minutes-only pickers, restricted time via onHourShow / onMinuteShow callbacks, and a custom locale (try "Change Locale").

TimeSelect eventBeforeShow / Close eventsOnly hoursOnly minutesRestricted time
Setting min. / max. time

Time picker supports minimum and maximum hours and minutes. They can also be set from JavaScript with the widget methods setMinTime(hour, minute) and setMaxTime(hour, minute).

Time range

Two time pickers select a chronological time range: the first is restricted to times before the one selected in the second, and vice versa. The JavaScript callbacks below also provide the restricted time used by the previous card.

Start time
End time

Usage


<style>
    .timepicker-column {
        padding: 0 1rem 1rem 0;
        vertical-align: top;
    }
</style>

<div class="card">
    <h5>Basic usage and three modes</h5>
    <p>Time picker has three modes: <code>inline</code>, <code>popup</code> and <code>spinner</code>. The spinner is the most convenient because it increments / decrements hours and minutes, but it is not compatible with <code>onHourShow</code> / <code>onMinuteShow</code>. The customized picker sets the time separator, start / end hours and minutes, the minute interval, buttons and more.</p>
    <h:form id="formBasicUsage">
        <p:messages id="messages"/>

        <h:panelGroup id="timePickerGroup" layout="block">
            <p>
                Inline mode
                <pe:timePicker value="#{timePickerController.time1}" mode="inline" widgetVar="inlineTimeWidget"
                               label="Inline time picker"/>
            </p>

            <p>
                Popup mode
                <pe:timePicker value="#{timePickerController.time2}" mode="popup" widgetVar="popupTimeWidget"
                               label="Popup time picker"/>
            </p>

            <p>
                Spinner mode
                <pe:timePicker value="#{timePickerController.time3}" widgetVar="spinnerTimeWidget"
                               label="Spinner time picker"/>
            </p>

            <p>
                Customization
                <pe:timePicker value="#{timePickerController.time4}" timeSeparator="-" startHours="8" endHours="20"
                               startMinutes="10" endMinutes="40" intervalMinutes="10" showCloseButton="true"
                               showDeselectButton="true" showNowButton="true" rows="3" showPeriod="true" size="8"
                               widgetVar="customTimeWidget" label="Custom time picker" required="true" requiredMessage="Customization is required!"/>
            </p>

            <p>
                Show popup by button
                <pe:timePicker value="#{timePickerController.time5}" mode="popup" widgetVar="popupBtnTimeWidget"
                               showOn="button" label="Popup time picker with button"/>
            </p>

            <p>
                Spinner with button
                <pe:timePicker value="#{timePickerController.time6}" mode="spinner" widgetVar="spinnerBtnTimeWidget"
                               showOn="button" label="Spinner time picker with button"/>
            </p>
        </h:panelGroup>

        <p:commandButton type="button" value="Disable time pickers" styleClass="mt-2 mr-2"
                         onclick="PF('inlineTimeWidget').disable();PF('popupTimeWidget').disable();
                             PF('spinnerTimeWidget').disable();PF('customTimeWidget').disable();
                             PF('popupBtnTimeWidget').disable();PF('spinnerBtnTimeWidget').disable();"/>
        <p:commandButton type="button" value="Enable time pickers" styleClass="mt-2 mr-2"
                         onclick="PF('inlineTimeWidget').enable();PF('popupTimeWidget').enable();
                             PF('spinnerTimeWidget').enable();PF('customTimeWidget').enable();
                             PF('popupBtnTimeWidget').enable();PF('spinnerBtnTimeWidget').enable();"/>
        <p:commandButton id="submitButton" value="Submit" actionListener="#{timePickerController.showTime}"
                         process="@this timePickerGroup" update="messages timeDialog timePickerGroup"
                         styleClass="mt-2 mr-2" icon="pi pi-save"/>

        <p:dialog id="timeDialog" header="Selected Values" visible="#{timePickerController.showTimeDialog}">
            <h:panelGrid columns="1" style="margin: 10px;">
                <h:outputText value="Inline: #{timePickerController.formattedTime1}"/>
                <h:outputText value="Popup: #{timePickerController.formattedTime2}"/>
                <h:outputText value="Spinner: #{timePickerController.formattedTime3}"/>
                <h:outputText value="Custom: #{timePickerController.formattedTime4}"/>
                <h:outputText value="Button: #{timePickerController.formattedTime5}"/>
                <h:outputText value="Spinner and Button: #{timePickerController.formattedTime6}"/>
            </h:panelGrid>
        </p:dialog>
    </h:form>
</div>

<div class="card">
    <h5>Advanced usage, events and callbacks</h5>
    <p>AJAX events <i>timeSelect</i>, <i>beforeShow</i> and <i>close</i>, hours-only and minutes-only pickers, restricted time via <code>onHourShow</code> / <code>onMinuteShow</code> callbacks, and a custom locale (try "Change Locale").</p>
    <h:form id="formAdvancedUsage">
        <p:growl id="growl" showDetail="true" showSummary="true"/>

        <h:panelGrid id="timePickerGrid" columns="5" columnClasses="timepicker-column">
            <h:outputText value="TimeSelect event"/>
            <h:outputText value="BeforeShow / Close events"/>
            <h:outputText value="Only hours"/>
            <h:outputText value="Only minutes"/>
            <h:outputText value="Restricted time"/>

            <pe:timePicker id="inlineTime" value="#{timePickerController.time1}" mode="inline" locale="#{timePickerController.locale}">
                <p:ajax event="timeSelect" listener="#{timePickerController.timeSelectListener}" update="growl"/>
            </pe:timePicker>
            <pe:timePicker id="spinnerTime" value="#{timePickerController.time2}" showPeriod="true" style="width: 100px;" locale="#{timePickerController.locale}">
                <p:ajax event="beforeShow" listener="#{timePickerController.beforeShowListener}" update="growl"/>
                <p:ajax event="close" listener="#{timePickerController.closeListener}" update="growl"/>
            </pe:timePicker>
            <pe:timePicker value="#{timePickerController.time4}" showMinutes="false" locale="#{timePickerController.locale}"/>
            <pe:timePicker value="#{timePickerController.time4}" showHours="false" locale="#{timePickerController.locale}"/>
            <pe:timePicker value="#{timePickerController.time4}" mode="popup" locale="#{timePickerController.locale}"
                           onHourShow="onHourShowCallback" onMinuteShow="onMinuteShowCallback"/>

            <p:commandButton id="localeButton" value="Change Locale" actionListener="#{timePickerController.changeLocale}"
                             process="@this" update="@parent" style="margin-top:10px;" icon="pi pi-save"/>
        </h:panelGrid>
    </h:form>

    <script>
        PrimeFacesExt.locales.TimePicker['pt_BR'] = {
            hourText: 'Horas',
            minuteText: 'Minutos',
            amPmText: ['AM', 'PM'],
            closeButtonText: 'Fechar',
            nowButtonText: 'Agora',
            deselectButtonText: 'Limpar seleção'
        };
    </script>
</div>

<div class="card">
    <h5>Setting min. / max. time</h5>
    <p>Time picker supports minimum and maximum hours and minutes. They can also be set from JavaScript with the widget methods <code>setMinTime(hour, minute)</code> and <code>setMaxTime(hour, minute)</code>.</p>
    <h:form id="formMinMaxTime">
        <pe:timePicker mode="inline" minHour="9" minMinute="15"
                       maxHour="16" maxMinute="30"/>
    </h:form>
</div>

<div class="card">
    <h5>Time range</h5>
    <p>Two time pickers select a chronological time range: the first is restricted to times before the one selected in the second, and vice versa. The JavaScript callbacks below also provide the restricted time used by the previous card.</p>
    <h:form id="formTimeRange">
        <h:panelGrid columns="5" cellpadding="4">
            <h:outputText value="Start time"/>
            <pe:timePicker value="#{timePickerController.time1}" mode="popup" onHourShow="tpStartOnHourShowCallback"
                           onMinuteShow="tpStartOnMinuteShowCallback" widgetVar="startTimeWidget"/>

            <h:panelGroup layout="block" style="width:20px;"/>

            <h:outputText value="End time"/>
            <pe:timePicker value="#{timePickerController.time2}" mode="popup" onHourShow="tpEndOnHourShowCallback"
                           onMinuteShow="tpEndOnMinuteShowCallback" widgetVar="endTimeWidget"/>
        </h:panelGrid>
    </h:form>

    <script>
        /* <![CDATA[ */
        function onHourShowCallback(hour) {
            if ((hour > 20) || (hour < 6)) {
                return false; // not valid
            }

            return true; // valid
        }

        function onMinuteShowCallback(hour, minute) {
            if ((hour == 20) && (minute >= 30)) {
                return false; // not valid
            }

            if ((hour == 6) && (minute < 30)) {
                return false; // not valid
            }

            return true;  // valid
        }

        function tpStartOnHourShowCallback(hour) {
            if (!PrimeFaces.widgets['endTimeWidget']) {
                return false;
            }

            var tpEndHour = parseInt(PF('endTimeWidget').getHours());

            // Check if proposed hour is prior or equal to selected end time hour
            if (parseInt(hour) <= tpEndHour) {
                return true;
            }

            // if hour did not match, it can not be selected
            return false;
        }

        function tpStartOnMinuteShowCallback(hour, minute) {
            if (!PrimeFaces.widgets['endTimeWidget']) {
                return false;
            }

            var tpEndHour = parseInt(PF('endTimeWidget').getHours());
            var tpEndMinute = parseInt(PF('endTimeWidget').getMinutes());

            // Check if proposed hour is prior to selected end time hour
            if (parseInt(hour) < tpEndHour) {
                return true;
            }

            // Check if proposed hour is equal to selected end time hour and minutes is prior
            if ((parseInt(hour) == tpEndHour) && (parseInt(minute) < tpEndMinute)) {
                return true;
            }

            // if minute did not match, it can not be selected
            return false;
        }

        function tpEndOnHourShowCallback(hour) {
            if (!PrimeFaces.widgets['startTimeWidget']) {
                return false;
            }

            var tpStartHour = parseInt(PF('startTimeWidget').getHours());

            // Check if proposed hour is after or equal to selected start time hour
            if (parseInt(hour) >= tpStartHour) {
                return true;
            }

            // if hour did not match, it can not be selected
            return false;
        }

        function tpEndOnMinuteShowCallback(hour, minute) {
            if (!PrimeFaces.widgets['startTimeWidget']) {
                return false;
            }

            var tpStartHour = parseInt(PF('startTimeWidget').getHours());
            var tpStartMinute = parseInt(PF('startTimeWidget').getMinutes());

            // Check if proposed hour is after selected start time hour
            if (parseInt(hour) > tpStartHour) {
                return true;
            }

            // Check if proposed hour is equal to selected start time hour and minutes is after
            if ((parseInt(hour) == tpStartHour) && (parseInt(minute) > tpStartMinute)) {
                return true;
            }

            // if minute did not match, it can not be selected
            return false;
        }
        /* ]]> */
    </script>
</div>