Package org.zkoss.zul

Class Timebox

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, org.zkoss.zk.ui.Component, org.zkoss.zk.ui.ext.Disable, org.zkoss.zk.ui.ext.Readonly, org.zkoss.zk.ui.ext.Scope, org.zkoss.zk.ui.sys.ComponentCtrl, Constrainted

    public class Timebox
    extends DateTimeFormatInputElement
    An input box for holding a time (a java.util.Date Object), but only Hour & Minute are used.

    Default getZclass(): z-timebox. (since 3.5.0)

    timebox supports below key events.

    • 0-9 : set the time digit depend on the position on the inner text box.
    • up : increase time digit depend on the position on the inner text box.
    • down : decrease time digit depend on the position on the inner text box.
    • delete : clear the time to empty (null)

    Like Combobox and Datebox, the value of a read-only time box (InputElement.isReadonly()) can be changed by clicking the up or down button (though users cannot type anything in the input box).

    Since 10.0.0, if cols is not set by user, it will match the formatted value at the beginning (or 5 when value is null).

    Since:
    3.0.0
    Author:
    Dennis Chen
    See Also:
    Serialized Form
    • Nested Class Summary

      • Nested classes/interfaces inherited from class org.zkoss.zk.ui.HtmlBasedComponent

        org.zkoss.zk.ui.HtmlBasedComponent.ExtraCtrl
      • Nested classes/interfaces inherited from class org.zkoss.zk.ui.AbstractComponent

        org.zkoss.zk.ui.AbstractComponent.Children, org.zkoss.zk.ui.AbstractComponent.ForwardInfo, org.zkoss.zk.ui.AbstractComponent.TargetInfo
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String DEFAULT_FORMAT  
      • Fields inherited from class org.zkoss.zk.ui.HtmlBasedComponent

        _zclass
      • Fields inherited from interface org.zkoss.zk.ui.Component

        APPLICATION_SCOPE, COMPONENT_SCOPE, DESKTOP_SCOPE, PAGE_SCOPE, REQUEST_SCOPE, SESSION_SCOPE, SPACE_SCOPE
      • Fields inherited from interface org.zkoss.zk.ui.sys.ComponentCtrl

        AFTER_CHILD_ADDED, AFTER_CHILD_REMOVED, AFTER_CLONED, AFTER_PAGE_ATTACHED, AFTER_PAGE_DETACHED, AFTER_PARENT_CHANGED, CE_BUSY_IGNORE, CE_DUPLICATE_IGNORE, CE_IMPORTANT, CE_NON_DEFERRABLE, CE_REPEAT_IGNORE
    • Constructor Summary

      Constructors 
      Constructor Description
      Timebox()  
      Timebox​(java.time.LocalDateTime value)  
      Timebox​(java.time.LocalTime value)  
      Timebox​(java.time.ZonedDateTime value)  
      Timebox​(java.util.Date date)  
    • Constructor Detail

      • Timebox

        public Timebox()
      • Timebox

        public Timebox​(java.util.Date date)
                throws org.zkoss.zk.ui.WrongValueException
        Throws:
        org.zkoss.zk.ui.WrongValueException
      • Timebox

        public Timebox​(java.time.ZonedDateTime value)
                throws org.zkoss.zk.ui.WrongValueException
        Throws:
        org.zkoss.zk.ui.WrongValueException
      • Timebox

        public Timebox​(java.time.LocalDateTime value)
                throws org.zkoss.zk.ui.WrongValueException
        Throws:
        org.zkoss.zk.ui.WrongValueException
      • Timebox

        public Timebox​(java.time.LocalTime value)
                throws org.zkoss.zk.ui.WrongValueException
        Throws:
        org.zkoss.zk.ui.WrongValueException
    • Method Detail

      • setFormat

        public void setFormat​(java.lang.String format)
                       throws org.zkoss.zk.ui.WrongValueException
        Sets the date format.

        If null or empty is specified, getDefaultFormat() is assumed. Since 5.0.7, you could specify one of the following reserved words, and DateFormats.getTimeFormat(int, java.util.Locale, java.lang.String) will be used to retrieve the real format.

        short DateFormats.getTimeFormat(int, java.util.Locale, java.lang.String) with DateFormat.SHORT
        medium DateFormats.getTimeFormat(int, java.util.Locale, java.lang.String) with DateFormat.MEDIUM
        long DateFormats.getTimeFormat(int, java.util.Locale, java.lang.String) with DateFormat.LONG
        full DateFormats.getTimeFormat(int, java.util.Locale, java.lang.String) with DateFormat.FULL

        In additions, the format could be a combination of the following pattern letters:

        Letter Date or Time Component Presentation Examples
        a Am/pm marker Text PM
        H Hour in day (0-23) Number 0
        k Hour in day (1-24) Number 24
        K Hour in am/pm (0-11) Number 0
        h Hour in am/pm (1-12) Number 12
        m Minute in hour Number 30
        s Second in minute Number 55
        Overrides:
        setFormat in class FormatInputElement
        Throws:
        org.zkoss.zk.ui.WrongValueException
        Since:
        5.0.0
      • getRealFormat

        public java.lang.String getRealFormat()
        Returns the real format, i.e., the combination of the format patterns, such as hh:mm.

        As described in setFormat(java.lang.String), a developer could specify an abstract name, such as short, or an empty string as the format, and this method will convert it to a real time format.

        Overrides:
        getRealFormat in class FormatInputElement
        Since:
        5.0.7
      • setValueInLocalDate

        public void setValueInLocalDate​(java.time.LocalDate value)
                                 throws org.zkoss.zk.ui.WrongValueException
        It is meaningless to set only LocalDate in timebox.
        Overrides:
        setValueInLocalDate in class DateTimeFormatInputElement
        Parameters:
        value - the date to be assigned to this component.
        Notice that, if this component does not allow users to select the time (i.e., the format limited to year, month and day), the date specified here is better to set hour, minutes, seconds and milliseconds to zero (for the current timezone, TimeZones.getCurrent()), so it is easier to work with other libraries, such as SQL. Dates has a set of utilities to simplify the task.
        Throws:
        org.zkoss.zk.ui.WrongValueException - if value is wrong
      • isButtonVisible

        public boolean isButtonVisible()
        Returns whether the button (on the right of the textbox) is visible.

        Default: true.

      • setButtonVisible

        public void setButtonVisible​(boolean visible)
        Sets whether the button (on the right of the textbox) is visible.
      • setConstraint

        public void setConstraint​(java.lang.String constr)
        Overrides:
        setConstraint in class InputElement
        Parameters:
        constr - a list of constraints separated by comma. Example: between 093000 and 183000, before 210000
      • getDefaultFormat

        protected java.lang.String getDefaultFormat()
        Returns the default format, which is used when constructing a timebox.

        Default: DateFormats.getTimeFormat(DEFAULT, null, "HH:mm") (see DateFormats.getTimeFormat(int, java.util.Locale, java.lang.String)).

        Though you might override this method to provide your own default format, it is suggested to specify the format for the current thread with DateFormats.setLocalFormatInfo(org.zkoss.text.DateFormatInfo).

        Since:
        5.0.7
      • getDateFormat

        protected java.text.DateFormat getDateFormat​(java.lang.String fmt)
        Returns the date format of the time only,

        Default: it uses SimpleDateFormat to format the date.

      • getZclass

        public java.lang.String getZclass()
        Overrides:
        getZclass in class org.zkoss.zk.ui.HtmlBasedComponent
      • renderProperties

        protected void renderProperties​(org.zkoss.zk.ui.sys.ContentRenderer renderer)
                                 throws java.io.IOException
        Overrides:
        renderProperties in class DateTimeFormatInputElement
        Throws:
        java.io.IOException
      • getPropertyAccess

        public org.zkoss.zk.ui.sys.PropertyAccess getPropertyAccess​(java.lang.String prop)
        Specified by:
        getPropertyAccess in interface org.zkoss.zk.ui.sys.ComponentCtrl
        Overrides:
        getPropertyAccess in class DateTimeFormatInputElement