Class Timebox
- java.lang.Object
-
- org.zkoss.zk.ui.AbstractComponent
-
- org.zkoss.zk.ui.HtmlBasedComponent
-
- 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
ComboboxandDatebox, 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
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringDEFAULT_FORMAT-
Fields inherited from class org.zkoss.zul.impl.DateTimeFormatInputElement
_locale, _tzone
-
Fields inherited from class org.zkoss.zul.impl.InputElement
_cols, _value
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.lang.ObjectcoerceFromString(java.lang.String value)Coerces the value passed toInputElement.setText(java.lang.String).protected java.lang.StringcoerceToString(java.lang.Object value)Coerces the value passed toInputElement.setText(java.lang.String).protected java.text.DateFormatgetDateFormat(java.lang.String fmt)Returns the date format of the time only,protected java.lang.StringgetDefaultFormat()Returns the default format, which is used when constructing a timebox.org.zkoss.zk.ui.sys.PropertyAccessgetPropertyAccess(java.lang.String prop)java.lang.StringgetRealFormat()Returns the real format, i.e., the combination of the format patterns, such as hh:mm.java.lang.StringgetZclass()booleanisButtonVisible()Returns whether the button (on the right of the textbox) is visible.protected voidrenderProperties(org.zkoss.zk.ui.sys.ContentRenderer renderer)voidsetButtonVisible(boolean visible)Sets whether the button (on the right of the textbox) is visible.voidsetConstraint(java.lang.String constr)voidsetFormat(java.lang.String format)Sets the date format.voidsetValueInLocalDate(java.time.LocalDate value)It is meaningless to set only LocalDate in timebox.-
Methods inherited from class org.zkoss.zul.impl.DateTimeFormatInputElement
getLocale, getTimeZone, getValue, getValueInLocalDate, getValueInLocalDateTime, getValueInLocalTime, getValueInZonedDateTime, getZoneId, setConstraint, setLocale, setLocale, setTimeZone, setTimeZone, setValue, setValueInLocalDateTime, setValueInLocalTime, setValueInZonedDateTime, toDate, toDate, toDate, toZonedDateTime
-
Methods inherited from class org.zkoss.zul.impl.FormatInputElement
getFormat
-
Methods inherited from class org.zkoss.zul.impl.InputElement
checkUserError, clearErrorMessage, clearErrorMessage, clone, getCols, getConstraint, getConstraintString, getErrorboxIconSclass, getErrorboxSclass, getErrorMessage, getInputAttributes, getInstant, getMaxlength, getName, getPlaceholder, getRawText, getRawValue, getTargetValue, getText, getType, isChildable, isDisabled, isInplace, isInstant, isMultiline, isReadonly, isValid, marshall, onWrongValue, select, service, setCols, setDisabled, setErrorboxIconSclass, setErrorboxSclass, setErrorMessage, setInplace, setInputAttributes, setInputAttributes, setInsertedText, setInstant, setMaxlength, setName, setPlaceholder, setRawValue, setReadonly, setSelectedText, setSelectionRange, setText, setValueDirectly, showCustomError, unmarshall, validate
-
Methods inherited from class org.zkoss.zul.impl.XulElement
getContext, getCtrlKeys, getPopup, getTooltip, setContext, setContext, setContextAttributes, setCtrlKeys, setPopup, setPopup, setPopupAttributes, setTooltip, setTooltip, setTooltipAttributes
-
Methods inherited from class org.zkoss.zk.ui.HtmlBasedComponent
addSclass, evalCSSFlex, focus, getAction, getClientAction, getDraggable, getDroppable, getExtraCtrl, getHeight, getHflex, getLeft, getRenderdefer, getSclass, getStyle, getTabindex, getTabindexInteger, getTooltiptext, getTop, getVflex, getWidth, getZindex, getZIndex, removeSclass, removeSclass, setAction, setClass, setClientAction, setDraggable, setDroppable, setFocus, setHeight, setHeight0, setHeightDirectly, setHflex, setHflex0, setHflexDirectly, setLeft, setLeftDirectly, setRenderdefer, setSclass, setStyle, setTabindex, setTabindex, setTooltiptext, setTop, setTopDirectly, setVflex, setVflex0, setVflexDirectly, setWidth, setWidth0, setWidthDirectly, setZclass, setZindex, setZIndex, setZIndexDirectly
-
Methods inherited from class org.zkoss.zk.ui.AbstractComponent
addAnnotation, addCallback, addClientEvent, addEventHandler, addEventListener, addEventListener, addForward, addForward, addForward, addForward, addMoved, addRedrawCallback, addScopeListener, addShadowRoot, addShadowRootBefore, addSharedEventHandlerMap, appendChild, applyProperties, beforeChildAdded, beforeChildRemoved, beforeParentChanged, destroyIndexCacheMap, detach, didActivate, didActivate, didDeserialize, didDeserialize, disableBindingAnnotation, disableClientUpdate, disableHostChanged, enableBindingAnnotation, enableHostChanged, getAnnotatedProperties, getAnnotatedPropertiesBy, getAnnotation, getAnnotations, getAnnotations, getAttribute, getAttribute, getAttribute, getAttributeOrFellow, getAttributes, getAttributes, getAuService, getAutag, getCallback, getChildren, getClientAttribute, getClientDataAttribute, getClientEvents, getDefaultMold, getDefinition, getDesktop, getEventHandler, getEventHandlerNames, getEventListenerMap, getEventListeners, getFellow, getFellow, getFellowIfAny, getFellowIfAny, getFellows, getFirstChild, getForwards, getId, getIndexCacheMap, getLastChild, getMold, getNextSibling, getPage, getParent, getPreviousSibling, getRedrawCallback, getRoot, getShadowFellowIfAny, getShadowRoots, getShadowVariable, getShadowVariable, getShadowVariable0, getSpaceOwner, getSpecialRendererOutput, getStubonly, getSubBindingAnnotationCount, getTemplate, getTemplateNames, getUuid, getWidgetAttributeNames, getWidgetClass, getWidgetListener, getWidgetListenerNames, getWidgetOverride, getWidgetOverrideNames, hasAttribute, hasAttribute, hasAttribute, hasAttributeOrFellow, hasBindingAnnotation, hasFellow, hasFellow, hasSubBindingAnnotation, initIndexCacheMap, insertBefore, invalidate, isDisabledHostChanged, isInitialized, isInvalidated, isListenerAvailable, isVisible, onChildAdded, onChildRemoved, onPageAttached, onPageDetached, onParentChanged, query, queryAll, redraw, redrawChildren, removeAttribute, removeAttribute, removeAttribute, removeCallback, removeChild, removeEventListener, removeForward, removeForward, removeRedrawCallback, removeScopeListener, removeShadowRoot, render, render, render, renderPropertiesOnly, replace, response, response, response, service, sessionDidActivate, sessionWillPassivate, setAttribute, setAttribute, setAttribute, setAuService, setAutag, setClientAttribute, setClientDataAttribute, setDefinition, setDefinition, setId, setMold, setPage, setPageBefore, setParent, setStubonly, setStubonly, setSubBindingAnnotationCount, setTemplate, setVisible, setVisibleDirectly, setWidgetClass, setWidgetListener, setWidgetOverride, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdateWidgetListener, smartUpdateWidgetOverride, toString, updateByClient, updateSubBindingAnnotationCount, willPassivate, willPassivate, willSerialize, willSerialize
-
-
-
-
Field Detail
-
DEFAULT_FORMAT
public static final java.lang.String DEFAULT_FORMAT
- See Also:
- Constant Field Values
-
-
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.WrongValueExceptionSets 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, andDateFormats.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)withDateFormat.SHORTmedium DateFormats.getTimeFormat(int, java.util.Locale, java.lang.String)withDateFormat.MEDIUMlong DateFormats.getTimeFormat(int, java.util.Locale, java.lang.String)withDateFormat.LONGfull DateFormats.getTimeFormat(int, java.util.Locale, java.lang.String)withDateFormat.FULLIn additions, the format could be a combination of the following pattern letters:
Letter Date or Time Component Presentation Examples aAm/pm marker Text PMHHour in day (0-23) Number 0kHour in day (1-24) Number 24KHour in am/pm (0-11) Number 0hHour in am/pm (1-12) Number 12mMinute in hour Number 30sSecond in minute Number 55- Overrides:
setFormatin classFormatInputElement- 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:
getRealFormatin classFormatInputElement- Since:
- 5.0.7
-
setValueInLocalDate
public void setValueInLocalDate(java.time.LocalDate value) throws org.zkoss.zk.ui.WrongValueExceptionIt is meaningless to set only LocalDate in timebox.- Overrides:
setValueInLocalDatein classDateTimeFormatInputElement- 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.Dateshas 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:
setConstraintin classInputElement- 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
-
coerceFromString
protected java.lang.Object coerceFromString(java.lang.String value) throws org.zkoss.zk.ui.WrongValueExceptionDescription copied from class:InputElementCoerces the value passed toInputElement.setText(java.lang.String).Deriving note:
If you want to store the value in other type, say BigDecimal, you have to overrideInputElement.coerceToString(java.lang.Object)andInputElement.coerceFromString(java.lang.String)to convert between a string and your targeting type.Moreover, when
Textboxis called, it calls this method with value = null. Derives shall handle this case properly.- Specified by:
coerceFromStringin classInputElement- Throws:
org.zkoss.zk.ui.WrongValueException
-
coerceToString
protected java.lang.String coerceToString(java.lang.Object value)
Description copied from class:InputElementCoerces the value passed toInputElement.setText(java.lang.String).Default: convert null to an empty string.
Deriving note:
If you want to store the value in other type, say BigDecimal, you have to overrideInputElement.coerceToString(java.lang.Object)andInputElement.coerceFromString(java.lang.String)to convert between a string and your targeting type.- Specified by:
coerceToStringin classInputElement
-
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:
getZclassin classorg.zkoss.zk.ui.HtmlBasedComponent
-
renderProperties
protected void renderProperties(org.zkoss.zk.ui.sys.ContentRenderer renderer) throws java.io.IOException- Overrides:
renderPropertiesin classDateTimeFormatInputElement- Throws:
java.io.IOException
-
getPropertyAccess
public org.zkoss.zk.ui.sys.PropertyAccess getPropertyAccess(java.lang.String prop)
- Specified by:
getPropertyAccessin interfaceorg.zkoss.zk.ui.sys.ComponentCtrl- Overrides:
getPropertyAccessin classDateTimeFormatInputElement
-
-