1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.x.form.validators;
14
15 import com.eviware.x.form.ValidationMessage;
16 import com.eviware.x.form.XFormField;
17 import com.eviware.x.form.XFormFieldValidator;
18
19 public class RequiredValidator implements XFormFieldValidator
20 {
21 private boolean trim;
22 private String message;
23
24 public RequiredValidator()
25 {
26 this.message = "Field requires a value";
27 }
28
29 public RequiredValidator( String message )
30 {
31 this.message = message;
32 }
33
34 public ValidationMessage[] validateField( XFormField formField )
35 {
36 String value = formField.getValue();
37 if( value == null || value.length() == 0 || ( trim && value.trim().length() == 0 ) )
38 {
39 return new ValidationMessage[] { new ValidationMessage( message, formField ) };
40 }
41
42 return null;
43 }
44
45 public boolean isTrim()
46 {
47 return trim;
48 }
49
50 public void setTrim( boolean trim )
51 {
52 this.trim = trim;
53 }
54 }