Class SimpleDateConstraint
- java.lang.Object
-
- org.zkoss.zul.SimpleConstraint
-
- org.zkoss.zul.AbstractSimpleDateTimeConstraint<java.util.Date>
-
- org.zkoss.zul.SimpleDateConstraint
-
- All Implemented Interfaces:
java.io.Serializable,ClientConstraint,Constraint
public class SimpleDateConstraint extends AbstractSimpleDateTimeConstraint<java.util.Date>
A simple date constraint.- Since:
- 3.0.2
- Author:
- tomyeh
- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from class org.zkoss.zul.AbstractSimpleDateTimeConstraint
_beg, _end, _tzone
-
Fields inherited from class org.zkoss.zul.SimpleConstraint
_finishParseCst, _flags, AFTER_END, AFTER_POINTER, AFTER_START, AT_POINTER, BEFORE_END, BEFORE_START, END_AFTER, END_BEFORE, NO_EMPTY, NO_FUTURE, NO_NEGATIVE, NO_PAST, NO_POSITIVE, NO_TODAY, NO_ZERO, OVERLAP, OVERLAP_AFTER, OVERLAP_BEFORE, OVERLAP_END, SERVER, START_AFTER, START_BEFORE, STRICT
-
-
Constructor Summary
Constructors Constructor Description SimpleDateConstraint(int flags)SimpleDateConstraint(int flags, java.lang.String errmsg)Constraints a constraint.SimpleDateConstraint(int flags, java.util.Date begin, java.util.Date end, java.lang.String errmsg)Constructs a constraint with beginning and ending date.SimpleDateConstraint(int flags, java.util.regex.Pattern regex, java.lang.String errmsg)Constructs a constraint combining regular expression.SimpleDateConstraint(java.lang.String constraint)Constructs a constraint with a list of constraints separated by comma.SimpleDateConstraint(java.util.regex.Pattern regex, java.lang.String errmsg)Constructs a regular-expression constraint.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidfixConstraint()static SimpleDateConstraintforTimeZone(java.lang.String constraint, java.util.TimeZone tzone)Builds aSimpleDateConstraintwhose date literals are parsed intzoneinstead of the JVM default.protected java.util.DateparseFrom(java.lang.String val)voidvalidate(org.zkoss.zk.ui.Component comp, java.lang.Object value)Verifies whether the value is acceptable.voidvalidateRange(org.zkoss.zk.ui.Component comp, java.util.Date begin, java.util.Date end)Validates a date range against this constraint's begin / end bounds.protected java.lang.StringvalueToString(org.zkoss.zk.ui.Component comp, java.util.Date value)-
Methods inherited from class org.zkoss.zul.AbstractSimpleDateTimeConstraint
getBeginDate, getEndDate, parseConstraint, setTimeZone, validate0
-
Methods inherited from class org.zkoss.zul.SimpleConstraint
getClientConstraint, getClientPackages, getErrorMessage, getFlags, getInstance, getRawValue
-
-
-
-
Constructor Detail
-
SimpleDateConstraint
public SimpleDateConstraint(int flags)
-
SimpleDateConstraint
public SimpleDateConstraint(int flags, java.lang.String errmsg)Constraints a constraint.- Parameters:
flags- a combination ofSimpleConstraint.NO_POSITIVE,SimpleConstraint.NO_NEGATIVE,SimpleConstraint.NO_ZERO, and so on.errmsg- the error message to display. Ignored if null or empty.
-
SimpleDateConstraint
public SimpleDateConstraint(java.util.regex.Pattern regex, java.lang.String errmsg)Constructs a regular-expression constraint.- Parameters:
regex- ignored if null or emptyerrmsg- the error message to display. Ignored if null or empty.- Since:
- 8.0.1
-
SimpleDateConstraint
public SimpleDateConstraint(int flags, java.util.regex.Pattern regex, java.lang.String errmsg)Constructs a constraint combining regular expression.- Parameters:
flags- a combination ofSimpleConstraint.NO_POSITIVE,SimpleConstraint.NO_NEGATIVE,SimpleConstraint.NO_ZERO, and so on.regex- ignored if null or emptyerrmsg- the error message to display. Ignored if null or empty.- Since:
- 8.0.1
-
SimpleDateConstraint
public SimpleDateConstraint(int flags, java.util.Date begin, java.util.Date end, java.lang.String errmsg)Constructs a constraint with beginning and ending date.- Parameters:
flags- a combination ofSimpleConstraint.NO_POSITIVE,SimpleConstraint.NO_NEGATIVE,SimpleConstraint.NO_ZERO, and so on.begin- the beginning date, or null if no constraint at the beginning date.end- the ending date, or null if no constraint at the ending date.errmsg- the error message to display. Ignored if null or empty.
-
SimpleDateConstraint
public SimpleDateConstraint(java.lang.String constraint)
Constructs a constraint with a list of constraints separated by comma.- Parameters:
constraint- a list of constraints separated by comma. Example: "between 20071012 and 20071223", "before 20080103"
-
-
Method Detail
-
forTimeZone
public static SimpleDateConstraint forTimeZone(java.lang.String constraint, java.util.TimeZone tzone)
Builds aSimpleDateConstraintwhose date literals are parsed intzoneinstead of the JVM default. Use this from components that expose their owntimeZoneproperty so the constraint bounds line up with the component's interpretation of "midnight" — e.g. a Daterangebox configured forAsia/Tokyoparsing"before 20260101"should anchor the bound to midnight Tokyo time, not the server's JVM default.This works because
SimpleConstraintparses lazily: the date literals are only consumed on the firstvalidate(org.zkoss.zk.ui.Component, java.lang.Object)call. TheAbstractSimpleDateTimeConstraint.setTimeZone(TimeZone)override resets the lazy-parse flag immediately after construction, so by the timeparseFrom(java.lang.String)runs the right zone is in place.Limitation. The supplied
tzonecontrols how the constraint's own date literals are parsed and how the candidate value is normalised inAbstractSimpleDateTimeConstraint.validate0(org.zkoss.zk.ui.Component, T), but theNO_PAST/NO_FUTURE/NO_TODAYflag checks performed bysuper.validatecompare againstDates.today()— i.e. today in the JVM-default zone — not against today-in-tzone. Near the date-line a value that is "today" intzonecan be "yesterday" or "tomorrow" in the JVM zone, so the flag verdict may differ from a user's zone-aware expectation. A fully zone-aware today-flag check is tracked as a separate enhancement.- Since:
- 10.4.0
-
fixConstraint
protected void fixConstraint()
- Specified by:
fixConstraintin classAbstractSimpleDateTimeConstraint<java.util.Date>
-
parseFrom
protected java.util.Date parseFrom(java.lang.String val) throws org.zkoss.zk.ui.UiException- Specified by:
parseFromin classAbstractSimpleDateTimeConstraint<java.util.Date>- Throws:
org.zkoss.zk.ui.UiException
-
validate
public void validate(org.zkoss.zk.ui.Component comp, java.lang.Object value) throws org.zkoss.zk.ui.WrongValueExceptionDescription copied from interface:ConstraintVerifies whether the value is acceptable.- Specified by:
validatein interfaceConstraint- Overrides:
validatein classAbstractSimpleDateTimeConstraint<java.util.Date>- Parameters:
comp- the component being validated- Throws:
org.zkoss.zk.ui.WrongValueException
-
validateRange
public void validateRange(org.zkoss.zk.ui.Component comp, java.util.Date begin, java.util.Date end) throws org.zkoss.zk.ui.WrongValueExceptionValidates a date range against this constraint's begin / end bounds.Semantics — per-endpoint, not range-as-whole. The single-value
validate(Component, Object)is applied tobeginand toendindependently. A "between 20260101 and 20261231" constraint accepts(2026-03-01, 2026-09-01)because each endpoint individually falls within the bound; it does NOT check whether the (begin, end) pair as a unit satisfies any cross-bound predicate (e.g. "the range must be wholly inside Q2"). Callers that need cross-bound rules should add them in their own component (Daterangebox usesminNights/maxNightsproperties for that purpose).Either end may be
nullfor open-ended ranges. When both are non-null, the range is also required to be non-reversed (begin≤end). Asymmetry with single-valuevalidate(Component, Object): anullendpoint here is silently skipped (soNO_EMPTYdoes not fire for it). Emptiness for range-aware components is governed by the component's ownallowEmptyproperty, not by base-class flags.Note: both ends are normalised via
Dates.beginOfDate(java.util.Date, java.util.TimeZone)before validation, so the time-of-day component is ignored. A constraint such as "before 2026-01-01 12:00" will be treated as "before 2026-01-01" for the end-of-range check — matching the existing single-valuevalidate(Component, Object)behaviour.- Parameters:
comp- the component (used for error message context)begin- the begin date, ornullif unboundedend- the end date, ornullif unbounded- Throws:
org.zkoss.zk.ui.WrongValueException- if either bound violates the constraint, or ifbeginis later thanend- Since:
- 10.4.0
-
valueToString
protected java.lang.String valueToString(org.zkoss.zk.ui.Component comp, java.util.Date value)- Specified by:
valueToStringin classAbstractSimpleDateTimeConstraint<java.util.Date>
-
-