01: package web.examples;
02:
03: import static org.jreform.criteria.Criteria.accept;
04: import static org.jreform.criteria.Criteria.length;
05: import static org.jreform.criteria.Criteria.range;
06: import static org.jreform.criteria.Criteria.regex;
07:
08: import org.jreform.HtmlForm;
09: import org.jreform.Input;
10:
11: /**
12: * User profile form.
13: */
14: public class UserProfileForm extends HtmlForm {
15: // Accepted format: 123-456-7890
16: private static final String PHONE_FORMAT = "^\\d{3}-\\d{3}-\\d{4}$";
17:
18: @SuppressWarnings("unchecked")
19: public UserProfileForm() {
20: // A text input that must be between 5 and 32 characters long
21: input(stringType(), "fullName", length(5, 32));
22:
23: // An integer field with a value between 18 and 99 inclusive
24: input(intType(), "age", range(18, 99));
25:
26: // A character field that accepts 'M' or 'F' only
27: input(charType(), "gender", accept('M', 'F'));
28:
29: // Optional phnoe number field that must match the specified regex
30: input(stringType(), "phone", regex(PHONE_FORMAT)).optional();
31: }
32:
33: /*
34: * Convenience methods to get input values.
35: */
36:
37: public Input<String> getFullName() {
38: return getInput("fullName");
39: }
40:
41: public Input<Integer> getAge() {
42: return getInput("age");
43: }
44:
45: public Input<Character> getGender() {
46: return getInput("gender");
47: }
48:
49: public Input<String> getPhone() {
50: return getInput("phone");
51: }
52:
53: }
|