Class SimpleConstraint
- All Implemented Interfaces:
Serializable,ClientConstraint,Constraint
- Direct Known Subclasses:
AbstractSimpleDateTimeConstraint,SimpleNumberInputConstraint
Depending on the component (such as Intbox and Datebox,
you could combine the flags, such as NO_POSITIVE + NO_ZERO
to accept only negative number.
- Author:
- tomyeh
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanprotected intThe constraints.static final intThe Error-box position.static final intThe Error-box position.static final intThe Error-box position.static final intThe Error-box position.static final intThe Error-box position.static final intThe Error-box position.static final intThe Error-box position.static final intThe Error-box position.static final intEmpty is not allowed.static final intDate in the future is not allowed.static final intNegative numbers are not allowed.static final intDate in the past is not allowed.static final intPositive numbers are not allowed.static final intToday is not allowed.static final intZero numbers are not allowed.static final intThe Error-box position.static final intThe Error-box position.static final intThe Error-box position.static final intThe Error-box position.static final intIndicates that this constraint requires immediate server validation.static final intThe Error-box position.static final intThe Error-box position.static final intThe value must match inside the data from ListModel only. -
Constructor Summary
ConstructorsConstructorDescriptionSimpleConstraint(int flags) Constructs a constraint with flags.SimpleConstraint(int flags, String errmsg) Constructs a constraint with flags and an error message.SimpleConstraint(int flags, Pattern regex, String errmsg) Constructs a constraint combining regular expression.SimpleConstraint(String constraint) Constructs a constraint with a list of constraints separated by comma.SimpleConstraint(Pattern regex, String errmsg) Constructs a regular-expression constraint. -
Method Summary
Modifier and TypeMethodDescriptionReturns the JavaScript snippet that will be evaluated at client to return a validator, or null if no client constraint is supported.Default: null (since it depends on zul.inp which is loaded for all input widgets).getErrorMessage(org.zkoss.zk.ui.Component comp) Returns the custom error message that shall be shown if an error occurs, or null if no custom error message specified.intgetFlags()static SimpleConstraintgetInstance(String constraint) Parses a list of constraints from a string to an integer representing a combination ofNO_POSITIVEand other flags.Returns the raw valueprotected intparseConstraint(String constraint) Parses a constraint into an integer value.voidVerifies whether the value is acceptable.
-
Field Details
-
NO_POSITIVE
public static final int NO_POSITIVEPositive numbers are not allowed.- See Also:
-
NO_NEGATIVE
public static final int NO_NEGATIVENegative numbers are not allowed.- See Also:
-
NO_ZERO
public static final int NO_ZEROZero numbers are not allowed.- See Also:
-
NO_EMPTY
public static final int NO_EMPTYEmpty is not allowed. If not specified, empty usually means null.- See Also:
-
STRICT
public static final int STRICTThe value must match inside the data from ListModel only.- See Also:
-
SERVER
public static final int SERVERIndicates that this constraint requires immediate server validation.If this flag is set, after client-side validation succeeds, the value will be immediately sent to the server for validation by calling
validate(org.zkoss.zk.ui.Component, java.lang.Object).If this flag is not set, the validated value will be queued similarly to regular unmonitored events and sent to the server at a later time.
- See Also:
-
NO_FUTURE
public static final int NO_FUTUREDate in the future is not allowed. (Only date part is compared)- See Also:
-
NO_PAST
public static final int NO_PASTDate in the past is not allowed. (Only date part is compared)- See Also:
-
NO_TODAY
public static final int NO_TODAYToday is not allowed. (Only date part is compared)- See Also:
-
BEFORE_START
public static final int BEFORE_STARTThe Error-box position.- See Also:
-
BEFORE_END
public static final int BEFORE_ENDThe Error-box position.- See Also:
-
END_BEFORE
public static final int END_BEFOREThe Error-box position.- See Also:
-
END_AFTER
public static final int END_AFTERThe Error-box position.- See Also:
-
AFTER_END
public static final int AFTER_ENDThe Error-box position.- See Also:
-
AFTER_START
public static final int AFTER_STARTThe Error-box position.- See Also:
-
START_AFTER
public static final int START_AFTERThe Error-box position.- See Also:
-
START_BEFORE
public static final int START_BEFOREThe Error-box position.- See Also:
-
OVERLAP
public static final int OVERLAPThe Error-box position.- See Also:
-
OVERLAP_END
public static final int OVERLAP_ENDThe Error-box position.- See Also:
-
OVERLAP_BEFORE
public static final int OVERLAP_BEFOREThe Error-box position.- See Also:
-
OVERLAP_AFTER
public static final int OVERLAP_AFTERThe Error-box position.- See Also:
-
AT_POINTER
public static final int AT_POINTERThe Error-box position.- See Also:
-
AFTER_POINTER
public static final int AFTER_POINTERThe Error-box position.- See Also:
-
_flags
protected int _flagsThe constraints. A combination ofNO_POSITIVEand others. -
_finishParseCst
protected boolean _finishParseCst
-
-
Constructor Details
-
SimpleConstraint
public SimpleConstraint(int flags) Constructs a constraint with flags.- Parameters:
flags- a combination ofNO_POSITIVE,NO_NEGATIVE,NO_ZERO, and so on.
-
SimpleConstraint
Constructs a constraint with flags and an error message.- Parameters:
flags- a combination ofNO_POSITIVE,NO_NEGATIVE,NO_ZERO, and so on.errmsg- the error message to display. Ignored if null or empty.
-
SimpleConstraint
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
-
SimpleConstraint
Constructs a constraint combining regular expression.- Parameters:
flags- a combination ofNO_POSITIVE,NO_NEGATIVE,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
-
SimpleConstraint
Constructs a constraint with a list of constraints separated by comma.- Parameters:
constraint- a list of constraints separated by comma. Example:no positive,no zero, or use '/' to enclose the regular expression as follows./.+@.+\.[a-z]+/: email only- Since:
- 3.0.2
-
-
Method Details
-
getInstance
Parses a list of constraints from a string to an integer representing a combination ofNO_POSITIVEand other flags.- Parameters:
constraint- a list of constraints separated by comma. Example: no positive, no zero
-
parseConstraint
Parses a constraint into an integer value. For example, "no positive" is parsed toNO_POSITIVE.Deriving classes might override this to provide more constraints.
- Throws:
org.zkoss.zk.ui.UiException- Since:
- 3.0.2
-
getFlags
public int getFlags()- Since:
- 3.0.2
-
getErrorMessage
Returns the custom error message that shall be shown if an error occurs, or null if no custom error message specified. -
validate
public void validate(org.zkoss.zk.ui.Component comp, Object value) throws org.zkoss.zk.ui.WrongValueException Description copied from interface:ConstraintVerifies whether the value is acceptable.- Specified by:
validatein interfaceConstraint- Parameters:
comp- the component being validated- Throws:
org.zkoss.zk.ui.WrongValueException
-
getClientConstraint
Description copied from interface:ClientConstraintReturns the JavaScript snippet that will be evaluated at client to return a validator, or null if no client constraint is supported. The validator is later used to validate an input.For example,
String getClientConstraint() { return "new foo.MyValidator()"; }Instead of return the snippet of JavaScript codes, it can return an instance of JavaScript string (enclosed with quotation), if the validator is zul.inp.SimpleConstraint.
For example,
String getClientConstraint() { return "'no empty'"; }The validator could implement the
validate, andshowCustomErrormethods, and an optional property,serverValidatemethods as follow.validateis required, whileshowCustomErrorandserverValidateare optional.String validate(Widget wgt, String value); Object showCustomError(Widget wgt, String errmsg); boolean serverValidate;Please refer to zul.inp.SimpleConstraint for details.
Notice that
CustomConstrainthas the higher priority thanClientConstraint. In other words,ClientConstraintis ignored if both defined.- Specified by:
getClientConstraintin interfaceClientConstraint- Returns:
- the code snippet that will be evaluated at client to return a validator.
-
getClientPackages
Default: null (since it depends on zul.inp which is loaded for all input widgets).- Specified by:
getClientPackagesin interfaceClientConstraint
-
getRawValue
Returns the raw value- Since:
- 10.0.0
-