org.zkoss.zul
Class SimpleConstraint

java.lang.Object
  extended by org.zkoss.zul.SimpleConstraint
All Implemented Interfaces:
java.io.Serializable, ClientConstraint, Constraint

public class SimpleConstraint
extends java.lang.Object
implements Constraint, ClientConstraint, java.io.Serializable

A simple constraint that you could build based the predefined constants.

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:
Serialized Form

Field Summary
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
          Postive numbers are not allowed.
static int NO_TODAY
          Today is not allowed.
static int NO_ZERO
          Zero numbers are not allowed.
 
Constructor Summary
SimpleConstraint(int flags)
           
SimpleConstraint(int flags, java.lang.String errmsg)
          Constraints a constraint.
SimpleConstraint(int flags, java.lang.String regex, java.lang.String errmsg)
          Constructs a constraint combining regular expression.
SimpleConstraint(java.lang.String regex, java.lang.String errmsg)
          Constructs a regular-expression constraint.
 
Method Summary
 java.lang.String getClientValidation()
          Returns the function name in JavaScript or a Javascript code snippet used to validate the value at the client, or null if no client verification is supported.
 java.lang.String getErrorMessage(org.zkoss.zk.ui.Component comp)
          Returns the error message when the client detects an error, or null if not specified.
static SimpleConstraint getInstance(java.lang.String flags)
          Parses flags from a string to an integer representing a combination of NO_POSITIVE and other NO_xxx flags.
 boolean isClientComplete()
          Returns whether the client's validation is complete.
 void validate(org.zkoss.zk.ui.Component comp, java.lang.Object value)
          Verifies whether the value is acceptable.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NO_POSITIVE

public static final int NO_POSITIVE
Postive 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

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
Constructor Detail

SimpleConstraint

public SimpleConstraint(int flags)

SimpleConstraint

public SimpleConstraint(int flags,
                        java.lang.String errmsg)
Constraints a constraint.

Parameters:
errmsg - the error message to display. Ignored if null or empty.

SimpleConstraint

public SimpleConstraint(java.lang.String regex,
                        java.lang.String errmsg)
Constructs a regular-expression constraint.

Parameters:
regex - ignored if null or empty
errmsg - the error message to display. Ignored if null or empty.

SimpleConstraint

public SimpleConstraint(int flags,
                        java.lang.String regex,
                        java.lang.String errmsg)
Constructs a constraint combining regular expression.

Parameters:
regex - ignored if null or empty
errmsg - the error message to display. Ignored if null or empty.
Method Detail

getInstance

public static final SimpleConstraint getInstance(java.lang.String flags)
Parses flags from a string to an integer representing a combination of NO_POSITIVE and other NO_xxx flags.

Parameters:
flags - a list of constraint separated by comma. Example: no positive, no zero

validate

public void validate(org.zkoss.zk.ui.Component comp,
                     java.lang.Object value)
              throws org.zkoss.zk.ui.WrongValueException
Description copied from interface: Constraint
Verifies whether the value is acceptable.

Specified by:
validate in interface Constraint
Parameters:
comp - the component being validated
Throws:
org.zkoss.zk.ui.WrongValueException

getClientValidation

public java.lang.String getClientValidation()
Description copied from interface: ClientConstraint
Returns the function name in JavaScript or a Javascript code snippet used to validate the value at the client, or null if no client verification is supported.

There are two formats of the return value:

Format 1:
Syntax: function_name
Example: "zkVld.noEmpty"
What Really Happens:
zkVld.noEmpty('id') is called at the client side to validate the input, where id is the component's identifier.

Format 2:
Syntax: function_name(arg1, arg2, arg3)
where arg could be #{EL_expression}
Example: "myValid(#{self},#{when},'more')"
What Really Happens:
myValid($e('id'),new Date('2007/06/03'),'more') is called at the client side to validate the input, where id is the component's identifier.

Specified by:
getClientValidation in interface ClientConstraint

getErrorMessage

public java.lang.String getErrorMessage(org.zkoss.zk.ui.Component comp)
Description copied from interface: ClientConstraint
Returns the error message when the client detects an error, or null if not specified.

It is used only if you want to override the default error message shown by the client. It won't affect the message caused by an exception thrown by Constraint.validate(org.zkoss.zk.ui.Component, java.lang.Object).

Specified by:
getErrorMessage in interface ClientConstraint

isClientComplete

public boolean isClientComplete()
Description copied from interface: ClientConstraint
Returns whether the client's validation is complete. If true, onChange won't be sent immediately (unless onChange is listened). If false, onChange is always sent no matter ClientConstraint.getClientValidation() return null or not.

Specified by:
isClientComplete in interface ClientConstraint


Copyright © 2005-2007 Potix Corporation. All Rights Reserved.