|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectfc.web.forms.FieldValidator
fc.web.forms.VText
public final class VText
Allows for various types of text validation. This class is meant to be
used with text based input types such as subclasses of AbstractText
Constructor Summary | |
---|---|
VText(AbstractText field,
java.lang.String errorMessage)
Creates a new validator that by default only fails validation if the field's value is empty, that is to say, it's not filled by the user or is filled only with spaces (since spaces are removed before validation). |
Method Summary | |
---|---|
VText |
allowEmpty(boolean allow)
Checks to see if the field is required to be filled by the user. |
VText |
allowFloatingOnly()
Ensures that the string is composed of only floating point number characters with optional leading/trailing blanks. |
VText |
allowIntegersOnly()
Ensures that the string is composed of only integer characters, with optional leading/trailing blanks. |
VText |
setAllowedChars(java.lang.String chars)
Sets the characters allowed in this field. |
VText |
setAllowedPattern(java.util.regex.Pattern pat)
Sets the regular expression representing the allowed input. |
VText |
setLengthRange(int minlength,
int maxlength)
Checks to see if the number of chars in the field are between the minimum and maximum amount (both inclusive). |
VText |
setMaxSize(int maxlength)
Checks to see if the number of chars in the field are between 0 and the specified maximum amount (inclusive). |
VText |
setMinSize(int minlength)
Checks to see if the number of chars in the field are at least the minimum number (inclusive) specified by this method. |
VText |
setUnallowedChars(java.lang.String chars)
Sets the characters not allowed in this field. |
java.lang.String |
toString()
|
void |
trimSpaces(boolean val)
If set to true, trims the string entered by the user before attempting to run further validation on it. |
boolean |
validate(FormData fd,
javax.servlet.http.HttpServletRequest req)
Validates the field in some fashion. |
Methods inherited from class fc.web.forms.FieldValidator |
---|
getErrorMessage, getField |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public VText(AbstractText field, java.lang.String errorMessage)
trimSpaces(boolean)
method.
Other methods in this class can be invoked for further kinds of validation.
Method Detail |
---|
public void trimSpaces(boolean val)
public VText allowEmpty(boolean allow)
This is useful, for example, if a field is required to be either
totally empty or filled with some sort of pattern as specified by setAllowedPattern(java.util.regex.Pattern)
. Note, however, that this method can get confusing if
a VFilled
validator is also attached to this field (which can be
done automatically by database objects generated by Generate
. In that case, 2 error messages will be shown to the
user if the field is left blank - one for the attached VFilled validator
and one for this one.
allow
- true to allow for an empty field
false otherwise (defaults to
true).
public VText allowIntegersOnly()
public VText allowFloatingOnly()
public VText setLengthRange(int minlength, int maxlength)
allowEmpty
method.
public VText setMaxSize(int maxlength)
setLengthRange(0, maxlength)
]
public VText setMinSize(int minlength)
public VText setUnallowedChars(java.lang.String chars)
setAllowedChars
method) and
unallowed (via this method), then unallowed characters have precedence and
if found in the input, the field will not be validated.
The same functionality can be achieved via regular expressions and negated character classes. It's a matter of preference.
After this method is called, the pattern previously set (if any) via the
setAllowedPattern(java.util.regex.Pattern)
method will be ignored for validation.
chars
- the unallowed chars. This parameter must not be null.
public VText setAllowedChars(java.lang.String chars)
allowEmpty
method.
After this method is called, the pattern previously set (if any) via the
setAllowedPattern(java.util.regex.Pattern)
method will be ignored for validation.
chars
- the allowed chars. This parameter must not be null.
public VText setAllowedPattern(java.util.regex.Pattern pat)
After this method is called, the string previously set (if any) via the
setAllowedChars(java.lang.String)
method will be ignored for validation.
pat
- the allowed pattern. Must not be null.
public java.lang.String toString()
toString
in class java.lang.Object
public boolean validate(FormData fd, javax.servlet.http.HttpServletRequest req)
FieldValidator
If there are validation error, stores the error in the formdata and returns false, otherwise returns true
validate
in class FieldValidator
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |