-
FEATURED COMPONENTS
First time here? Check out the FAQ!
I have been trying to find an answer to this but have not had too much luck. Maybe I am not familiar enough with the terminology to search well, I am very new to ZK.
I have a form that has all the text and combo boxes have "no empty" constraints on them. The problem I am having, when I enter some information in these boxes and then try to clear them, whether it be because they entered a bunch of junk and want to start over, or they submitted the form and I want it cleared out in case they want to enter another record. But everytime I attempt to clear, the values stay in the boxes and I get error on the first text box saying that I need to have a value in it. "This field may not be empty or have just spaces in it".
Is there any way to clear the form without triggering that constraint?
Thanks in advance!
You can (at least for textbox/intbox and so on) use setRawValue("") or setRawValue(null) to avoid the constraint check (or You could disable the constraint while setting the values and the set the constarints again)
It depends on what kind of custom constarints You want to set up? If You want to make Your own constraint classes, I have done a couple of these successfully - look into the Constraint interface.
Basically You implement the Constraint interface and implements the validate(Component c, Object value) method so that it throws a WrongValueException if the constraint is not fulfilled:
public class MyConstraint implements Constraint { public void validate(Component arg0, Object arg1) throws WrongValueException { if (arg1 == null || !valid(arg1)) // valid is a method that returns false if argument fails the constraint { throw new WrongValueException(arg0, "Bummer!"); } } private boolean valid(Object value) { // Do some checks and return true/false depending on the outcome - in this case just check if not null return (value != null); } }
Asked: 2009-12-21 07:10:58 +0800
Seen: 1,419 times
Last updated: Mar 27 '10