Class NumberInputElement

All Implemented Interfaces:
Serializable, Cloneable, Component, Disable, Readonly, Scope, ComponentCtrl, Constrainted
Direct Known Subclasses:
Decimalbox, Doublebox, Doublespinner, Intbox, Longbox, Spinner

public abstract class NumberInputElement extends FormatInputElement
A skeletal implementation for number-type input box.
Author:
tomyeh
See Also:
  • Constructor Details

    • NumberInputElement

      public NumberInputElement()
  • Method Details

    • setRoundingMode

      public void setRoundingMode(int mode)
      Sets the rounding mode. Note: You cannot change the rounding mode unless you are using Java 6 or later.
      Parameters:
      mode - the rounding mode. Allowed value: BigDecimal.ROUND_CEILING, BigDecimal.ROUND_DOWN, BigDecimal.ROUND_FLOOR, BigDecimal.ROUND_HALF_DOWN, BigDecimal.ROUND_HALF_UP, BigDecimal.ROUND_HALF_EVEN, BigDecimal.ROUND_UNNECESSARY and BigDecimal.ROUND_UP
      Throws:
      UnsupportedOperationException - if Java 5 or below
    • setRoundingMode

      public void setRoundingMode(String name)
      Sets the rounding mode by the name. Note: You cannot change the rounding mode unless you are using Java 6 or later.
      Parameters:
      name - the rounding mode's name. Allowed value:
      CEILING
      Rounding mode to round towards positive infinity.
      DOWN
      Rounding mode to round towards zero.
      FLOOR
      Rounding mode to round towards negative infinity.
      HALF_DOWN
      Rounding mode to round towards "nearest neighbor" unless both neighbors are equidistant, in which case round down.
      HALF_EVEN
      Rounding mode to round towards the "nearest neighbor" unless both neighbors are equidistant, in which case, round towards the even neighbor.
      HALF_UP
      Rounding mode to round towards "nearest neighbor" unless both neighbors are equidistant, in which case round up.
      UNNECESSARY
      Rounding mode to assert that the requested operation has an exact result, hence no rounding is necessary.
      UP
      Rounding mode to round away from zero.
      Throws:
      UnsupportedOperationException - if Java 5 or below
      See Also:
    • getRoundingMode

      public int getRoundingMode()
      Returns the rounding mode.

      Default: BigDecimal.ROUND_HALF_EVEN.

    • getLocale

      public Locale getLocale()
      Returns the locale associated with this number input element, or null if Locales.getCurrent() is preferred.
      Since:
      5.0.8
    • setLocale

      public void setLocale(Locale locale)
      Sets the locale used to identify the symbols of this number input element.

      Default: null (i.e., Locales.getCurrent(), the current locale is assumed)

      If the format of FormatInputElement.getFormat() is null, the format is assumed from getDefaultFormat(). (since 5.0.9)

      Since:
      5.0.8
    • setLocale

      public void setLocale(String locale)
      Sets the locale used to identify the symbols of this number input element.

      Default: null (i.e., Locales.getCurrent(), the current locale is assumed)

      Since:
      5.0.8
    • isLocaleFormat

      protected boolean isLocaleFormat()
      Returns if the "locale:" in FormatInputElement.getFormat() is presented.
      Since:
      9.5.1
    • getDefaultLocale

      protected Locale getDefaultLocale()
      Returns the default locale, either getLocale() or Locales.getCurrent() (never null). It is useful when you wan to get a locale for this input.
      Since:
      5.0.10
    • renderProperties

      protected void renderProperties(ContentRenderer renderer) throws IOException
      Description copied from class: HtmlBasedComponent
      Renders the content of this component, excluding the enclosing tags and children.

      See also ZK Client-side Reference: Property Rendering

      Overrides:
      renderProperties in class FormatInputElement
      Throws:
      IOException
    • getDefaultFormat

      protected String getDefaultFormat()
      Return a default format for the number input element when the locale is specified.

      Default: ##,##0.##, you can overwrite this by specifying the following setting in zk.xml

      
      	<library-property>
      		<name>org.zkoss.zul.numberFormat</name>
      		<value>##,##0.##</value>
      	</library-property>
       
      Since:
      5.0.9
      See Also:
    • formatNumber

      protected String formatNumber(Object value, String defaultFormat)
      Formats a number (Integer, BigDecimal...) into a string. If null, an empty string is returned.

      A utility to assist the handling of numeric data.

      Parameters:
      defaultFormat - used if FormatInputElement.getFormat() returns null. If defaultFormat and FormatInputElement.getFormat() are both null, the system's default format is used.
      See Also:
    • toNumberOnly

      protected Object[] toNumberOnly(String val)
      Filters out non digit characters, such comma and whitespace, from the specified value. It is designed to let user enter data in more free style. They may or may not enter data in the specified format.
      Returns:
      a two element array. The first element is the string to parse with, say, Double.parseDouble. The second element is an integer to indicate how many digits the result shall be scaled. For example, if the second element is 2. Then, the result shall be divided with 10 ^ 2.
      See Also:
    • getPropertyAccess

      public PropertyAccess getPropertyAccess(String prop)
      Description copied from interface: ComponentCtrl
      Returns the corresponding property access object from the given property name, if any.
      Specified by:
      getPropertyAccess in interface ComponentCtrl
      Overrides:
      getPropertyAccess in class FormatInputElement
      Parameters:
      prop - the name of the property
      Returns:
      null it means not to support for the property name.