KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * ProjectForm.java
3  */

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

25
26
27 public final class ProjectForm extends ActionForm {
28     
29     // --------------------------------------------------- Instance Variables
30

31     /**
32      * The name of the project
33      */

34     private String JavaDoc name = null;
35
36     /**
37      * The name of the oldproject
38      */

39     private String JavaDoc oldName = null;
40
41
42     
43     // ----------------------------------------------------------- Properties
44

45    
46     /**
47      * Get the name
48      *@return String
49      */

50     public String JavaDoc getName() {
51         return (name);
52     }
53
54     /**
55      * Set the name
56      * @param name
57      */

58     public void setName(String JavaDoc name) {
59         this.name = name;
60     }
61
62     /**
63      * Get the oldname
64      *@return String
65      */

66     public String JavaDoc getOldName() {
67         return (oldName);
68     }
69
70     /**
71      * Set the oldname
72      * @param oldname
73      */

74     public void setOldName(String JavaDoc oldName) {
75         this.oldName = oldName;
76     }
77
78     // --------------------------------------------------------- Public Methods
79

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

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

102     public ActionErrors validate(ActionMapping mapping,
103                                  HttpServletRequest JavaDoc request) {
104         ActionErrors errors = new ActionErrors();
105         if (name == null || name.length()==0)
106             errors.add("name",
107                    new ActionError("error.projectname.required"));
108
109         if (oldName == null || oldName.length()==0)
110             errors.add("olName",
111                    new ActionError("error.oldName.required"));
112
113         return (errors);
114     }
115
116
117
118 }
119
120
Popular Tags