public class SimpleConstraint extends java.lang.Object implements Constraint, ClientConstraint, java.io.Serializable
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.
Modifier and Type | Field and Description |
---|---|
protected int |
_flags
The constraints.
|
static int |
AFTER_END
The Error-box position.
|
static int |
AFTER_POINTER
The Error-box position.
|
static int |
AFTER_START
The Error-box position.
|
static int |
AT_POINTER
The Error-box position.
|
static int |
BEFORE_END
The Error-box position.
|
static int |
BEFORE_START
The Error-box position.
|
static int |
END_AFTER
The Error-box position.
|
static int |
END_BEFORE
The Error-box position.
|
static int |
NO_EMPTY
Empty is not allowed.
|
static int |
NO_FUTURE
Date in the future is not allowed.
|
static int |
NO_NEGATIVE
Negative numbers are not allowed.
|
static int |
NO_PAST
Date in the past is not allowed.
|
static int |
NO_POSITIVE
Positive numbers are not allowed.
|
static int |
NO_TODAY
Today is not allowed.
|
static int |
NO_ZERO
Zero numbers are not allowed.
|
static int |
OVERLAP
The Error-box position.
|
static int |
OVERLAP_AFTER
The Error-box position.
|
static int |
OVERLAP_BEFORE
The Error-box position.
|
static int |
OVERLAP_END
The Error-box position.
|
static int |
SERVER
Indicates this constraint requires the server validation.
|
static int |
START_AFTER
The Error-box position.
|
static int |
START_BEFORE
The Error-box position.
|
static int |
STRICT
The value must match inside the data from ListModel only.
|
Constructor and 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.lang.String 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.lang.String regex,
java.lang.String errmsg)
Constructs a regular-expression constraint.
|
Modifier and Type | Method and Description |
---|---|
java.lang.String |
getClientConstraint()
Returns the JavaScript snippet that will be evaluated at client
to return a validator, or null if no client constraint is supported.
|
java.lang.String |
getClientPackages()
Default: null (since it depends on zul.inp which is loaded for
all input widgets).
|
java.lang.String |
getErrorMessage(Component comp)
Returns the custom error message that shall be shown if an error occurs,
or null if no custom error message specified.
|
int |
getFlags()
|
static SimpleConstraint |
getInstance(java.lang.String constraint)
Parses a list of constraints from a string to an integer
representing a combination of
NO_POSITIVE and other flags. |
protected int |
parseConstraint(java.lang.String constraint)
Parses a constraint into an integer value.
|
void |
validate(Component comp,
java.lang.Object value)
Verifies whether the value is acceptable.
|
public static final int NO_POSITIVE
public static final int NO_NEGATIVE
public static final int NO_ZERO
public static final int NO_EMPTY
public static final int STRICT
public static final int SERVER
validate(org.zkoss.zk.ui.Component, java.lang.Object)
.
It is useful if the result of the regular expressions is different
at the client (with JavaScript) and the server with ava).public static final int NO_FUTURE
public static final int NO_PAST
public static final int NO_TODAY
public static final int BEFORE_START
public static final int BEFORE_END
public static final int END_BEFORE
public static final int END_AFTER
public static final int AFTER_END
public static final int AFTER_START
public static final int START_AFTER
public static final int START_BEFORE
public static final int OVERLAP
public static final int OVERLAP_END
public static final int OVERLAP_BEFORE
public static final int OVERLAP_AFTER
public static final int AT_POINTER
public static final int AFTER_POINTER
protected int _flags
NO_POSITIVE
and others.public SimpleConstraint(int flags)
flags
- a combination of NO_POSITIVE
, NO_NEGATIVE
,
NO_ZERO
, and so on.public SimpleConstraint(int flags, java.lang.String errmsg)
flags
- a combination of NO_POSITIVE
, NO_NEGATIVE
,
NO_ZERO
, and so on.errmsg
- the error message to display. Ignored if null or empty.public SimpleConstraint(java.lang.String regex, java.lang.String errmsg)
regex
- ignored if null or emptyerrmsg
- the error message to display. Ignored if null or empty.public SimpleConstraint(int flags, java.lang.String regex, java.lang.String errmsg)
flags
- a combination of NO_POSITIVE
, NO_NEGATIVE
,
NO_ZERO
, and so on.regex
- ignored if null or emptyerrmsg
- the error message to display. Ignored if null or empty.public SimpleConstraint(java.lang.String constraint)
constraint
- a list of constraints separated by comma.
Example: no positive, no zeropublic static SimpleConstraint getInstance(java.lang.String constraint)
NO_POSITIVE
and other flags.constraint
- a list of constraints separated by comma.
Example: no positive, no zeroprotected int parseConstraint(java.lang.String constraint) throws UiException
NO_POSITIVE
.
Deriving classes might override this to provide more constraints.
UiException
public int getFlags()
public java.lang.String getErrorMessage(Component comp)
public void validate(Component comp, java.lang.Object value) throws WrongValueException
Constraint
validate
in interface Constraint
comp
- the component being validatedWrongValueException
public java.lang.String getClientConstraint()
ClientConstraint
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
,
and showCustomError
methods, and an optional property,
serverValidate
methods as follow. validate
is required,
while showCustomError
and serverValidate
are 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 CustomConstraint
has the higher priority than
ClientConstraint
. In other words, ClientConstraint
is ignored if both defined.
getClientConstraint
in interface ClientConstraint
public java.lang.String getClientPackages()
getClientPackages
in interface ClientConstraint
Copyright © 2005-2011 Potix Corporation. All Rights Reserved.