001: package hero.struts.forms;
002:
003: import javax.servlet.http.HttpServletRequest;
004: import org.apache.struts.action.ActionError;
005: import org.apache.struts.action.ActionErrors;
006: import org.apache.struts.action.ActionForm;
007: import org.apache.struts.action.ActionMapping;
008:
009: /**
010: * Form bean for the BnUser. This form has the following fields,
011: * with default values in square brackets:
012: * <ul>
013: * <li><b>name</b> - The name of the user. [REQUIRED]
014: * <li><b>password</b> - The password for this user. [REQUIRED]
015: * <li><b>email</b> - The email [REQUIRED]
016: * </ul>
017: *
018: * @author Miguel Valdes Faura
019: * @version $Revision: 1.1 $ $Date: 2004/07/30 14:57:57 $
020: */
021:
022: public final class UserForm extends ActionForm {
023:
024: // =================================================== Instance Variables
025:
026: /**
027: * The user name
028: */
029: private String name = null;
030:
031: /**
032: * The password of the user
033: */
034:
035: private String password = null;
036:
037: /**
038: * The email of the user
039: */
040:
041: private String email = null;
042:
043: /**
044: * The jabber address of the user
045: */
046:
047: private String jabber = null;
048:
049: // =========================================================== Properties
050:
051: /**
052: * Return the name
053: */
054: public String getName() {
055:
056: return (this .name);
057:
058: }
059:
060: /**
061: * Set the name
062: *
063: */
064: public void setName(String name) {
065:
066: this .name = name;
067:
068: }
069:
070: /**
071: * Return the password
072: */
073: public String getPassword() {
074:
075: return (this .password);
076:
077: }
078:
079: /**
080: * Set the password
081: *
082: */
083: public void setPassword(String password) {
084:
085: this .password = password;
086:
087: }
088:
089: /**
090: * Return the email
091: */
092: public String getEmail() {
093:
094: return (this .email);
095:
096: }
097:
098: /**
099: * Set the email
100: *
101: */
102: public void setEmail(String email) {
103:
104: this .email = email;
105:
106: }
107:
108: /**
109: * Return the jabber address
110: */
111: public String getJabber() {
112:
113: return (this .jabber);
114:
115: }
116:
117: /**
118: * Set the jabber address
119: *
120: */
121: public void setJabber(String jabber) {
122:
123: this .jabber = jabber;
124:
125: }
126:
127: // --------------------------------------------------------- Public Methods
128:
129: /**
130: * Reset all properties to their default values.
131: *
132: * @param mapping The mapping used to select this instance
133: * @param request The servlet request we are processing
134: */
135: public void reset(ActionMapping mapping, HttpServletRequest request) {
136:
137: this .name = null;
138: this .password = null;
139: this .email = null;
140: this .jabber = null;
141: }
142:
143: /**
144: * Validate the properties that have been set from this HTTP request,
145: * and return an <code>ActionErrors</code> object that encapsulates any
146: * validation errors that have been found. If no errors are found, return
147: * <code>null</code> or an <code>ActionErrors</code> object with no
148: * recorded error messages.
149: *
150: * @param mapping The mapping used to select this instance
151: * @param request The servlet request we are processing
152: */
153: public ActionErrors validate(ActionMapping mapping,
154: HttpServletRequest request) {
155:
156: ActionErrors errors = new ActionErrors();
157:
158: if (name == null || name.length() == 0)
159: errors.add("name", new ActionError(
160: "error.username.required"));
161: if (password == null || password.length() == 0)
162: errors.add("password", new ActionError(
163: "error.password.required"));
164: if (email == null || email.length() == 0)
165: errors
166: .add("email", new ActionError(
167: "error.email.required"));
168: if (jabber == null || jabber.length() == 0)
169: errors.add("jabber", new ActionError(
170: "error.jabber.required"));
171:
172: return (errors);
173:
174: }
175: }
|