KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > hero > struts > forms > PropertyForm


1 package hero.struts.forms;
2
3 import javax.servlet.http.HttpServletRequest JavaDoc;
4 import org.apache.struts.action.ActionError;
5 import org.apache.struts.action.ActionErrors;
6 import org.apache.struts.action.ActionForm;
7 import org.apache.struts.action.ActionMapping;
8
9 /**
10  * Form bean for property. This form has the following fields,
11  * with default values in square brackets:
12  * <ul>
13  * <li><b>key</b> - The property key. [REQUIRED]
14  * <li><b>value</b> - The property value. [REQUIRED]
15  * </ul>
16  *
17  * @author Miguel Valdes Faura
18  * @version $Revision: 1.1 $ $Date: 2004/07/30 14:57:57 $
19  */

20
21 public final class PropertyForm extends ActionForm {
22
23     // --------------------------------------------------- Instance Variables
24

25     /**
26      * The property key.
27      */

28     private String JavaDoc key = null;
29
30
31     /**
32      * The property value
33      */

34     private String JavaDoc value = null;
35
36
37     // ----------------------------------------------------------- Properties
38

39     /**
40      * Return the property key.
41      */

42     public String JavaDoc getKey() {
43
44     return (this.key);
45     }
46
47     /**
48      * Set the property key.
49      *
50      * @param key The new property key
51      */

52     public void setKey(String JavaDoc key) {
53
54         this.key = key;
55     }
56
57     /**
58      * Return the property value.
59      */

60     public String JavaDoc getValue() {
61
62     return (this.value);
63     }
64
65     /**
66      * Set the property value.
67      *
68      * @param value The new property value
69      */

70     public void setValue(String JavaDoc value) {
71
72         this.value = value;
73     }
74
75
76     // --------------------------------------------------------- Public Methods
77

78
79     /**
80      * Reset all properties to their default values.
81      *
82      * @param mapping The mapping used to select this instance
83      * @param request The servlet request we are processing
84      */

85     public void reset(ActionMapping mapping, HttpServletRequest JavaDoc request) {
86
87         this.key = null;
88         this.value = null;
89     }
90
91     /**
92      * Validate the properties that have been set from this HTTP request,
93      * and return an <code>ActionErrors</code> object that encapsulates any
94      * validation errors that have been found. If no errors are found, return
95      * <code>null</code> or an <code>ActionErrors</code> object with no
96      * recorded error messages.
97      *
98      * @param mapping The mapping used to select this instance
99      * @param request The servlet request we are processing
100      */

101     public ActionErrors validate(ActionMapping mapping, HttpServletRequest JavaDoc request) {
102
103         ActionErrors errors = new ActionErrors();
104
105         if (key == null || key.length()==0)
106         errors.add("key", new ActionError("error.key.required"));
107         if (value == null || value.length()==0)
108         errors.add("value", new ActionError("error.value.required"));
109
110     return (errors);
111
112     }
113 }
114
Popular Tags