• 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

Calculator

Calculator is a highly configurable component that attaches a popup calculator to an input field. Features include a Scientific or Standard button layout, localization and RTL support, and it works with any input field including InputNumber. Based on jQuery Calculator by Keith Wood.

Calculator Tag Documentation

Calculator is a popup calculator component that attaches to an input field.

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.
dir String false ltr Defines text direction, valid values are ltr and rtl.
for String false Search expression for the target input component to attach the calculator to.
layout String false standard Layout of the calculator: 'standard' or 'horizontal'.
locale Object false Locale for number formatting. Can be a string or java.util.Locale instance.
onbutton String false Client-side callback when a calculator button is activated.
onclose String false Client-side callback when the calculator panel is closed.
onopen String false Client-side callback when the calculator panel is opened.
precision Integer false 10 Decimal precision (number of decimal places).
showOn String false focus When to show the calculator: 'focus', 'button', or 'both'.
style String false Inline style of the component.
styleClass String false Style class of the component.
Tag Documentation Widget Source
Basic Usage

Attach a calculator to h:inputText, p:inputText and p:inputNumber. It can be embedded in the input component or configured externally with for.

Calculator with defaults on h:inputText
Calculator scientific layout on a p:inputText
Calculator with button on a p:inputNumber
Localization and RTL

Calculator can be localized. Select a language to change the text and tooltips. RTL (right to left) is supported as well.

Advanced Usage, events and callbacks

Control the calculator from JavaScript, use the onopen, onclose and onbutton callbacks and handle the server side open, close and button events with p:ajax.

Event Result
Event Result

Usage


<div class="card">
    <h5>Basic Usage</h5>
    <p>Attach a calculator to <code>h:inputText</code>, <code>p:inputText</code> and <code>p:inputNumber</code>. It can be embedded in the input component or configured externally with <code>for</code>.</p>
    <h:form id="formBasicUsage">
        <h:panelGrid columns="2" cellpadding="4">
            <h:outputText value="Calculator with defaults on h:inputText"/>
            <h:inputText id="hInputText" value="#{calculatorController.hInputText}">
                <pe:calculator/>
            </h:inputText>

            <h:outputText value="Calculator scientific layout on a p:inputText"/>
            <p:inputText id="pInputText" value="#{calculatorController.pInputText}">
                <pe:calculator layout="scientific"/>
            </p:inputText>

            <h:outputText value="Calculator with button on a p:inputNumber"/>
            <p:inputNumber id="pInputNumber" value="#{calculatorController.pInputNumber}" symbol=" $USD" symbolPosition="s"
                           decimalSeparator="." thousandSeparator="," decimalPlaces="2"/>
        </h:panelGrid>

        <pe:calculator for="pInputNumber" showOn="both" precision="2"/>
    </h:form>
</div>

<div class="card">
    <h5>Localization and RTL</h5>
    <p>Calculator can be localized. Select a language to change the text and tooltips. RTL (right to left) is supported as well.</p>
    <h:form id="formLocalization">
        <p:messages id="msgLocalization"/>
        <h:panelGrid columns="6" id="pnlDetails" cellpadding="4">
            <p:outputLabel value="Locale:" for="cboLocale"/>
            <p:selectOneMenu id="cboLocale" value="#{calculatorController.language}" style="width:200px" required="true">
                <f:selectItems value="#{calculatorController.languages}"/>
                <p:ajax update="pInputText msgLocalization" process="@this"/>
            </p:selectOneMenu>

            <p:outputLabel value="RTL:" for="chkRtl"/>
            <p:selectBooleanCheckbox id="chkRtl" value="#{calculatorController.rtl}">
                <p:ajax update="pInputText msgLocalization" process="@this"/>
            </p:selectBooleanCheckbox>

            <p:outputLabel value="Calc:" for="pInputText"/>
            <p:inputText id="pInputText" value="#{calculatorController.pInputText}">
                <pe:calculator dir="#{calculatorController.rtl ? 'rtl' : 'ltr'}" locale="#{calculatorController.language}" showOn="both"/>
            </p:inputText>
        </h:panelGrid>
    </h:form>
</div>

<div class="card">
    <h5>Advanced Usage, events and callbacks</h5>
    <p>Control the calculator from JavaScript, use the <code>onopen</code>, <code>onclose</code> and <code>onbutton</code> callbacks and handle the server side <i>open</i>, <i>close</i> and <i>button</i> events with <code>p:ajax</code>.</p>
    <h:form id="formJavascript">
        <p:growl id="growl" showDetail="true" showSummary="true"/>

        <h:panelGrid columns="3" cellpadding="4">
            <p:outputLabel value="Callback: onOpen and onClose"/>
            <p:inputText id="txtOnOpenClose" value="867">
                <pe:calculator id="calculator1" widgetVar="calc1" showOn="both"
                               onopen="$(PrimeFaces.escapeClientId('formJavascript:lblOnOpenClose')).text('Open Event: ' + value);"
                               onclose="$(PrimeFaces.escapeClientId('formJavascript:lblOnOpenClose')).text('Close Event: ' + value);">
                    <p:ajax event="open" listener="#{calculatorController.openListener}" update="growl"/>
                    <p:ajax event="close" listener="#{calculatorController.closeListener}" update="growl"/>
                    <p:ajax event="button" listener="#{calculatorController.buttonListener}" update="growl"/>
                </pe:calculator>
            </p:inputText>
            <h:outputText id="lblOnOpenClose" value="Event Result" style="font-weight:bold"/>

            <p:outputLabel value="Callback: onButton"/>
            <p:inputText widgetVar="txtOnButton" value="5309">
                <pe:calculator id="calculator2" widgetVar="calc2" showOn="both"
                               onbutton="$(PrimeFaces.escapeClientId('formJavascript:lblOnButton')).text('Button: ' + label + ' Current Value: ' + value)">
                    <p:ajax event="button" listener="#{calculatorController.buttonListener}" update="growl"/>
                </pe:calculator>
            </p:inputText>
            <h:outputText id="lblOnButton" value="Event Result" style="font-weight:bold"/>
        </h:panelGrid>

        <div class="mt-3">
            <p:commandButton value="Show" type="button" onclick="PF('calc1').show();"/>
            <p:commandButton value="Hide" type="button" onclick="PF('calc1').hide();"/>
            <p:commandButton value="Disable" type="button" onclick="PF('calc1').disable();PF('calc2').disable();"/>
            <p:commandButton value="Enable" type="button" onclick="PF('calc1').enable();PF('calc2').enable();"/>
            <p:commandButton value="Destroy" type="button" onclick="PF('calc1').destroy();PF('calc2').destroy();"/>
        </div>
    </h:form>
</div>