Class SimpleConstraint
- java.lang.Object
-
- org.zkoss.zul.SimpleConstraint
-
- All Implemented Interfaces:
java.io.Serializable,ClientConstraint,Constraint
- Direct Known Subclasses:
AbstractSimpleDateTimeConstraint,SimpleNumberInputConstraint
public class SimpleConstraint extends java.lang.Object implements Constraint, ClientConstraint, java.io.Serializable
The default constraint supporting no empty, regular expressions and so on.Depending on the component (such as
IntboxandDatebox, you could combine the flags, such asNO_POSITIVE+NO_ZEROto accept only negative number.- Author:
- tomyeh
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean_finishParseCstprotected int_flagsThe constraints.static intAFTER_ENDThe Error-box position.static intAFTER_POINTERThe Error-box position.static intAFTER_STARTThe Error-box position.static intAT_POINTERThe Error-box position.static intBEFORE_ENDThe Error-box position.static intBEFORE_STARTThe Error-box position.static intEND_AFTERThe Error-box position.static intEND_BEFOREThe Error-box position.static intNO_EMPTYEmpty is not allowed.static intNO_FUTUREDate in the future is not allowed.static intNO_NEGATIVENegative numbers are not allowed.static intNO_PASTDate in the past is not allowed.static intNO_POSITIVEPositive numbers are not allowed.static intNO_TODAYToday is not allowed.static intNO_ZEROZero numbers are not allowed.static intOVERLAPThe Error-box position.static intOVERLAP_AFTERThe Error-box position.static intOVERLAP_BEFOREThe Error-box position.static intOVERLAP_ENDThe Error-box position.static intSERVERIndicates that this constraint requires immediate server validation.static intSTART_AFTERThe Error-box position.static intSTART_BEFOREThe Error-box position.static intSTRICTThe value must match inside the data from ListModel only.
-
Constructor Summary
Constructors Constructor Description SimpleConstraint(int flags)Constructs a constraint with flags.SimpleConstraint(int flags, java.lang.String errmsg)Constructs a constraint with flags and an error message.SimpleConstraint(int flags, java.util.regex.Pattern regex, java.lang.String errmsg)Constructs a constraint combining regular expression.SimpleConstraint(java.lang.String constraint)Constructs a constraint with a list of constraints separated by comma.SimpleConstraint(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 java.lang.StringgetClientConstraint()Returns the JavaScript snippet that will be evaluated at client to return a validator, or null if no client constraint is supported.java.lang.StringgetClientPackages()Default: null (since it depends on zul.inp which is loaded for all input widgets).java.lang.StringgetErrorMessage(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(java.lang.String constraint)Parses a list of constraints from a string to an integer representing a combination ofNO_POSITIVEand other flags.java.lang.StringgetRawValue()Returns the raw valueprotected intparseConstraint(java.lang.String constraint)Parses a constraint into an integer value.voidvalidate(org.zkoss.zk.ui.Component comp, java.lang.Object value)Verifies whether the value is acceptable.
-
-
-
Field Detail
-
NO_POSITIVE
public static final int NO_POSITIVE
Positive numbers are not allowed.- See Also:
- Constant Field Values
-
NO_NEGATIVE
public static final int NO_NEGATIVE
Negative numbers are not allowed.- See Also:
- Constant Field Values
-
NO_ZERO
public static final int NO_ZERO
Zero numbers are not allowed.- See Also:
- Constant Field Values
-
NO_EMPTY
public static final int NO_EMPTY
Empty is not allowed. If not specified, empty usually means null.- See Also:
- Constant Field Values
-
STRICT
public static final int STRICT
The value must match inside the data from ListModel only.- See Also:
- Constant Field Values
-
SERVER
public static final int SERVER
Indicates 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:
- Constant Field Values
-
NO_FUTURE
public static final int NO_FUTURE
Date in the future is not allowed. (Only date part is compared)- See Also:
- Constant Field Values
-
NO_PAST
public static final int NO_PAST
Date in the past is not allowed. (Only date part is compared)- See Also:
- Constant Field Values
-
NO_TODAY
public static final int NO_TODAY
Today is not allowed. (Only date part is compared)- See Also:
- Constant Field Values
-
BEFORE_START
public static final int BEFORE_START
The Error-box position.- See Also:
- Constant Field Values
-
BEFORE_END
public static final int BEFORE_END
The Error-box position.- See Also:
- Constant Field Values
-
END_BEFORE
public static final int END_BEFORE
The Error-box position.- See Also:
- Constant Field Values
-
END_AFTER
public static final int END_AFTER
The Error-box position.- See Also:
- Constant Field Values
-
AFTER_END
public static final int AFTER_END
The Error-box position.- See Also:
- Constant Field Values
-
AFTER_START
public static final int AFTER_START
The Error-box position.- See Also:
- Constant Field Values
-
START_AFTER
public static final int START_AFTER
The Error-box position.- See Also:
- Constant Field Values
-
START_BEFORE
public static final int START_BEFORE
The Error-box position.- See Also:
- Constant Field Values
-
OVERLAP
public static final int OVERLAP
The Error-box position.- See Also:
- Constant Field Values
-
OVERLAP_END
public static final int OVERLAP_END
The Error-box position.- See Also:
- Constant Field Values
-
OVERLAP_BEFORE
public static final int OVERLAP_BEFORE
The Error-box position.- See Also:
- Constant Field Values
-
OVERLAP_AFTER
public static final int OVERLAP_AFTER
The Error-box position.- See Also:
- Constant Field Values
-
AT_POINTER
public static final int AT_POINTER
The Error-box position.- See Also:
- Constant Field Values
-
AFTER_POINTER
public static final int AFTER_POINTER
The Error-box position.- See Also:
- Constant Field Values
-
_flags
protected int _flags
The constraints. A combination ofNO_POSITIVEand others.
-
_finishParseCst
protected boolean _finishParseCst
-
-
Constructor Detail
-
SimpleConstraint
public SimpleConstraint(int flags)
Constructs a constraint with flags.- Parameters:
flags- a combination ofNO_POSITIVE,NO_NEGATIVE,NO_ZERO, and so on.
-
SimpleConstraint
public SimpleConstraint(int flags, java.lang.String errmsg)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
public SimpleConstraint(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
-
SimpleConstraint
public SimpleConstraint(int flags, java.util.regex.Pattern regex, java.lang.String errmsg)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
public SimpleConstraint(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:no positive,no zero, or use '/' to enclose the regular expression as follows./.+@.+\.[a-z]+/: email only- Since:
- 3.0.2
-
-
Method Detail
-
getInstance
public static SimpleConstraint getInstance(java.lang.String constraint)
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
protected int parseConstraint(java.lang.String constraint) throws org.zkoss.zk.ui.UiExceptionParses 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
public java.lang.String 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.
-
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- Parameters:
comp- the component being validated- Throws:
org.zkoss.zk.ui.WrongValueException
-
getClientConstraint
public java.lang.String 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
public java.lang.String getClientPackages()
Default: null (since it depends on zul.inp which is loaded for all input widgets).- Specified by:
getClientPackagesin interfaceClientConstraint
-
getRawValue
public java.lang.String getRawValue()
Returns the raw value- Since:
- 10.0.0
-
-