public class Datebox extends FormatInputElement
The default format (FormatInputElement.getFormat()
) depends on DateFormats.getDateFormat(int, java.util.Locale, java.lang.String)
and the current user's locale (unless setLocale(java.util.Locale)
is assigned.
Please refer to setFormat(java.lang.String)
for more details.
Default getZclass()
: z-datebox.(since 3.5.0)
Modifier and Type | Class and Description |
---|---|
protected class |
Datebox.ExtraCtrl
A utility class to implement
HtmlBasedComponent.getExtraCtrl() . |
_value
AFTER_PAGE_ATTACHED, AFTER_PAGE_DETACHED
Constructor and Description |
---|
Datebox() |
Datebox(Date date)
Constructor with a given date.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes the calendar if it was dropped down.
|
protected Object |
coerceFromString(String value)
Coerces the value passed to
InputElement.setText(java.lang.String) . |
protected String |
coerceToString(Object value)
Coerces the value passed to
InputElement.setText(java.lang.String) . |
protected DateFormat |
getDateFormat(String fmt)
Returns the date format of the specified format
|
protected String |
getDefaultFormat()
Returns the default format, which is used when constructing a datebox,
or when
setFormat(java.lang.String) is called with null or empty. |
List<TimeZone> |
getDisplayedTimeZones()
Returns a list of the time zones that will be displayed at the
client and allow user to select.
|
Object |
getExtraCtrl() |
Locale |
getLocale()
Returns the locale associated with this datebox,
or null if
Locales.getCurrent() is preferred. |
protected String |
getLocalizedFormat()
Returns the localized format, which is used when constructing a datebox.
|
String |
getPosition() |
org.zkoss.zk.ui.sys.PropertyAccess |
getPropertyAccess(String prop) |
String |
getRealFormat()
Returns the real format, i.e., the combination of the format patterns,
such as yyyy-MM-dd.
|
boolean |
getShowTodayLink()
Returns whether enable to show the link that jump to today in day view
|
TimeZone |
getTimeZone()
Returns the time zone that this date box belongs to, or null if the
default time zone is used.
|
String |
getTodayLinkLabel()
Returns the label of the link that jump to today in day view
|
Date |
getValue()
Returns the value (in Date), might be null unless a constraint stops it.
|
String |
getZclass() |
boolean |
isButtonVisible()
Returns whether the button (on the right of the textbox) is visible.
|
boolean |
isCompact()
Deprecated.
As of release 5.0.0, it is no longer supported.
|
boolean |
isLenient()
Returns whether or not date/time parsing is to be lenient.
|
boolean |
isTimeZonesReadonly()
Returns whether the list of the time zones to display is readonly.
|
boolean |
isWeekOfYear()
Returns whether enable to show the week number in the current calendar or not.
|
protected Object |
marshall(Object value)
Marshall value to be sent to the client if needed.
|
void |
open()
Drops down the calendar to select a date.
|
protected void |
renderProperties(org.zkoss.zk.ui.sys.ContentRenderer renderer) |
void |
service(org.zkoss.zk.au.AuRequest request,
boolean everError)
Processes an AU request.
|
void |
setButtonVisible(boolean visible)
Sets whether the button (on the right of the textbox) is visible.
|
void |
setCompact(boolean compact)
Deprecated.
As of release 5.0.0, it is no longer supported.
|
void |
setConstraint(String constr) |
void |
setDisplayedTimeZones(List<TimeZone> dtzones)
Sets a list of the time zones that will be displayed at the
client and allow user to select.
|
void |
setDisplayedTimeZones(String dtzones)
Sets a concatenation of a list of the time zones' ID, separated by comma,
that will be displayed at the client and allow user to select.
|
void |
setFormat(String format)
Sets the date format.
|
void |
setLenient(boolean lenient)
Sets whether or not date/time parsing is to be lenient.
|
void |
setLocale(Locale locale)
Sets the locale used to identify the format of this datebox.
|
void |
setLocale(String locale)
Sets the locale used to identify the format of this datebox.
|
void |
setOpen(boolean open)
Drops down or closes the calendar to select a date.
|
void |
setPosition(String position)
Position the popup datebox to the specified location.
|
void |
setShowTodayLink(boolean showTodayLink)
Sets whether enable to show the link that jump to today in day view
|
void |
setTimeZone(String id)
Sets the time zone that this date box belongs to, or null if
the default time zone is used.
|
void |
setTimeZone(TimeZone tzone)
Sets the time zone that this date box belongs to, or null if
the default time zone is used.
|
void |
setTimeZonesReadonly(boolean readonly)
Sets whether the list of the time zones to display is readonly.
|
void |
setTodayLinkLabel(String todayLinkLabel)
Sets the label of the link that jump to today in day view
|
void |
setValue(Date value)
Sets the value (in Date).
|
void |
setWeekOfYear(boolean weekOfYear)
Sets whether enable to show the week number in the current calendar or
not.
|
static int |
toStyle(String format)
Returns the styling index, or -111 if not matched.
|
protected Object |
unmarshall(Object value)
Unmarshall value returned from client if needed.
|
getFormat
checkUserError, clearErrorMessage, clearErrorMessage, clone, getCols, getConstraint, getErrorboxIconSclass, getErrorboxSclass, getErrorMessage, getInstant, getMaxlength, getName, getPlaceholder, getRawText, getRawValue, getTargetValue, getText, getType, isChildable, isDisabled, isInplace, isInstant, isMultiline, isReadonly, isValid, onWrongValue, select, setCols, setConstraint, setDisabled, setErrorboxIconSclass, setErrorboxSclass, setErrorMessage, setInplace, setInstant, setMaxlength, setName, setPlaceholder, setRawValue, setReadonly, setSelectedText, setSelectionRange, setText, setValueDirectly, showCustomError, validate
getContext, getCtrlKeys, getPopup, getTooltip, setContext, setContext, setContextAttributes, setCtrlKeys, setPopup, setPopup, setPopupAttributes, setTooltip, setTooltip, setTooltipAttributes
focus, getAction, getDraggable, getDroppable, getHeight, getHflex, getLeft, getRenderdefer, getSclass, getStyle, getTabindex, getTabindexInteger, getTooltiptext, getTop, getVflex, getWidth, getZindex, getZIndex, setAction, setClass, 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
addAnnotation, addAnnotation, addCallback, addClientEvent, addEventHandler, addEventListener, addEventListener, addForward, addForward, addForward, addForward, addMoved, addRedrawCallback, addScopeListener, addShadowRoot, addShadowRootBefore, addSharedEventHandlerMap, appendChild, applyProperties, beforeChildAdded, beforeChildRemoved, beforeParentChanged, detach, didActivate, didActivate, didDeserialize, didDeserialize, disableBindingAnnotation, disableClientUpdate, enableBindingAnnotation, equals, getAnnotatedProperties, getAnnotatedPropertiesBy, getAnnotation, getAnnotation, getAnnotations, 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, getId, getLastChild, getListenerIterator, getMold, getNextSibling, getPage, getParent, getPreviousSibling, getRedrawCallback, getRoot, getShadowFellowIfAny, getShadowRoots, getShadowVariable, getShadowVariable, getShadowVariable0, getSpaceOwner, getSpecialRendererOutput, getStubonly, getSubBindingAnnotationCount, getTemplate, getTemplateNames, getUuid, getWidgetAttribute, getWidgetAttributeNames, getWidgetClass, getWidgetListener, getWidgetListenerNames, getWidgetOverride, getWidgetOverrideNames, hasAttribute, hasAttribute, hasAttribute, hasAttributeOrFellow, hasBindingAnnotation, hasFellow, hasFellow, hasSubBindingAnnotation, insertBefore, invalidate, isInvalidated, isListenerAvailable, isVisible, onChildAdded, onChildRemoved, onPageAttached, onPageDetached, query, queryAll, redraw, redrawChildren, removeAttribute, removeAttribute, removeAttribute, removeCallback, removeChild, removeEventListener, removeForward, removeForward, removeRedrawCallback, removeScopeListener, removeShadowRoot, render, render, render, 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, setWidgetAttribute, setWidgetClass, setWidgetListener, setWidgetOverride, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdateWidgetListener, smartUpdateWidgetOverride, toString, updateByClient, updateSubBindingAnnotationCount, willPassivate, willPassivate, willSerialize, willSerialize
public Datebox()
public Datebox(Date date) throws org.zkoss.zk.ui.WrongValueException
date
- the date to be assigned to this datebox initially.TimeZones.getCurrent()
), so it is easier
to work with other libraries, such as SQL.
Dates
has a set of utilities to simplify the task.org.zkoss.zk.ui.WrongValueException
public void setWeekOfYear(boolean weekOfYear)
public boolean isWeekOfYear()
Default: false
protected String getDefaultFormat()
setFormat(java.lang.String)
is called with null or empty.
Default: DateFormats.getDateFormat(DEFAULT, null, "yyyy/MM/dd")
(see DateFormats.getDateFormat(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)
.
protected String getLocalizedFormat()
You might override this method to provide your own localized format.
public boolean isLenient()
With lenient parsing, the parser may use heuristics to interpret inputs that do not precisely match this object's format. With strict parsing, inputs must match this object's format.
public void setLenient(boolean lenient)
Default: true.
With lenient parsing, the parser may use heuristics to interpret inputs that do not precisely match this object's format. With strict parsing, inputs must match this object's format.
public boolean isCompact()
public void setCompact(boolean compact)
public boolean isButtonVisible()
Default: true.
public void setButtonVisible(boolean visible)
public String getPosition()
public void setPosition(String position)
position
- where to position. Default: after_start
Allowed values:
public Date getValue() throws org.zkoss.zk.ui.WrongValueException
org.zkoss.zk.ui.WrongValueException
- if user entered a wrong valuepublic void setValue(Date value) throws org.zkoss.zk.ui.WrongValueException
value
- the date to be assigned to this datebox.TimeZones.getCurrent()
), so it is easier
to work with other libraries, such as SQL.
Dates
has a set of utilities to simplify the task.org.zkoss.zk.ui.WrongValueException
- if value is wrongpublic void setFormat(String format) throws org.zkoss.zk.ui.WrongValueException
If null or empty is specified, getDefaultFormat()
is assumed.
Since 5.0.7, you could specify one of the following reserved words,
and DateFormats.getDateFormat(int, java.util.Locale, java.lang.String)
or DateFormats.getDateTimeFormat(int, int, java.util.Locale, java.lang.String)
will be used to retrieve the real format.
short | DateFormats.getDateFormat(int, java.util.Locale, java.lang.String) with DateFormat.SHORT |
medium | DateFormats.getDateFormat(int, java.util.Locale, java.lang.String) with DateFormat.MEDIUM |
long | DateFormats.getDateFormat(int, java.util.Locale, java.lang.String) with DateFormat.LONG |
full | DateFormats.getDateFormat(int, java.util.Locale, java.lang.String) with DateFormat.FULL |
To specify a date/time format, you could specify two reserved words, separated
by a plus. For example, "medium+short" means
DateFormats.getDateTimeFormat(int, int, java.util.Locale, java.lang.String)
with the medium date styling and
the short time styling.
In additions, the format could be a combination of the following pattern letters:
Letter | Date or Time Component | Presentation | Examples |
---|---|---|---|
G
| Era designator | Text | AD
|
y
| Year | Year | 1996 ; 96
|
M
| Month in year | Month | July ; Jul ; 07
|
w
| Week in year (starting at 1) | Number | 27
|
W
| Week in month (starting at 1) | Number | 2
|
D
| Day in year (starting at 1) | Number | 189
|
d
| Day in month (starting at 1) | Number | 10
|
F
| Day of week in month | Number | 2
|
E
| Day in week | Text | Tuesday ; Tue
|
setFormat
in class FormatInputElement
org.zkoss.zk.ui.WrongValueException
public static int toStyle(String format)
public String getRealFormat()
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 date/time format.
getRealFormat
in class FormatInputElement
public TimeZone getTimeZone()
The default time zone is determined by TimeZones.getCurrent()
.
public void setTimeZone(TimeZone tzone)
The default time zone is determined by TimeZones.getCurrent()
.
Notice that if getDisplayedTimeZones()
was called with
a non-empty list, the time zone must be one of it.
Otherwise (including tzone is null),
the first timezone is selected.
public void setTimeZone(String id)
The default time zone is determined by TimeZones.getCurrent()
.
id
- the time zone's ID, such as "America/Los_Angeles".
The time zone will be retrieved by calling TimeZone.getTimeZone(id).public List<TimeZone> getDisplayedTimeZones()
Default: null
public void setDisplayedTimeZones(List<TimeZone> dtzones)
If the getTimeZone()
is null,
the first time zone in the list is assumed.
dtzones
- a list of the time zones to display.
If empty, it assumed to be null.public void setDisplayedTimeZones(String dtzones)
The time zone is retrieved by calling TimeZone.getTimeZone().
dtzones
- a concatenation of a list of the timezones' ID, such as
"America/Los_Angeles,GMT+8"
setDisplayedTimeZones(List)
public boolean isTimeZonesReadonly()
public void setTimeZonesReadonly(boolean readonly)
public Locale getLocale()
Locales.getCurrent()
is preferred.public void setLocale(Locale locale)
Default: null (i.e., Locales.getCurrent()
, the current locale
is assumed)
public void setLocale(String locale)
Default: null (i.e., Locales.getCurrent()
, the current locale
is assumed)
public void setOpen(boolean open)
public void open()
public void close()
public void service(org.zkoss.zk.au.AuRequest request, boolean everError)
Default: in addition to what are handled by HtmlBasedComponent.service(org.zkoss.zk.au.AuRequest, boolean)
,
it also handles onTimeZoneChange, onChange, onChanging and onError.
service
in interface org.zkoss.zk.ui.sys.ComponentCtrl
service
in class InputElement
public Object getExtraCtrl()
getExtraCtrl
in interface org.zkoss.zk.ui.sys.ComponentCtrl
getExtraCtrl
in class org.zkoss.zk.ui.HtmlBasedComponent
public void setConstraint(String constr)
setConstraint
in class InputElement
constr
- a list of constraints separated by comma.
Example: "between 20071012 and 20071223", "before 20080103"protected Object marshall(Object value)
InputElement
Overrides it if the value to be sent to the client is not JSON Compatible.
marshall
in class InputElement
value
- the value to be sent to the clientprotected Object unmarshall(Object value)
InputElement
Overrides it if the value returned is not JSON Compatible.
unmarshall
in class InputElement
value
- the value returned from clientprotected Object coerceFromString(String value) throws org.zkoss.zk.ui.WrongValueException
InputElement
InputElement.setText(java.lang.String)
.
Deriving note:
If you want to store the value in other type, say BigDecimal,
you have to override InputElement.coerceToString(java.lang.Object)
and InputElement.coerceFromString(java.lang.String)
to convert between a string and your targeting type.
Moreover, when Textbox
is called, it calls this method
with value = null. Derives shall handle this case properly.
coerceFromString
in class InputElement
org.zkoss.zk.ui.WrongValueException
protected String coerceToString(Object value)
InputElement
InputElement.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 override InputElement.coerceToString(java.lang.Object)
and InputElement.coerceFromString(java.lang.String)
to convert between a string and your targeting type.
coerceToString
in class InputElement
protected DateFormat getDateFormat(String fmt)
Default: it uses SimpleDateFormat to format the date.
fmt
- the pattern.public String getZclass()
getZclass
in class org.zkoss.zk.ui.HtmlBasedComponent
public boolean getShowTodayLink()
Default: false
public void setShowTodayLink(boolean showTodayLink)
showTodayLink
- show or hiddenpublic String getTodayLinkLabel()
Default: Today
public void setTodayLinkLabel(String todayLinkLabel)
todayLinkLabel
- today link labelpublic org.zkoss.zk.ui.sys.PropertyAccess getPropertyAccess(String prop)
getPropertyAccess
in interface org.zkoss.zk.ui.sys.ComponentCtrl
getPropertyAccess
in class FormatInputElement
protected void renderProperties(org.zkoss.zk.ui.sys.ContentRenderer renderer) throws IOException
renderProperties
in class FormatInputElement
IOException
Copyright © 2017. All rights reserved.