View Javadoc

1   /*
2    * Copyright 1999-2001,2004 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  
18  package org.apache.struts.webapp.example;
19  
20  
21  import javax.servlet.http.HttpServletRequest;
22  import org.apache.struts.action.ActionErrors;
23  import org.apache.struts.action.ActionMessage;
24  import org.apache.struts.action.ActionForm;
25  import org.apache.struts.action.ActionMapping;
26  
27  
28  /***
29   * Form bean for the user profile page.  This form has the following fields,
30   * with default values in square brackets:
31   * <ul>
32   * <li><b>password</b> - Entered password value
33   * <li><b>username</b> - Entered username value
34   * </ul>
35   *
36   * @author Craig R. McClanahan
37   * @version $Rev: 421493 $ $Date: 2006-07-12 20:52:31 -0700 (Wed, 12 Jul 2006) $
38   */
39  
40  public final class LogonForm extends ActionForm {
41  
42  
43      // --------------------------------------------------- Instance Variables
44  
45  
46      /***
47       * The password.
48       */
49      private String password = null;
50  
51  
52      /***
53       * The username.
54       */
55      private String username = null;
56  
57  
58      // ----------------------------------------------------------- Properties
59  
60  
61      /***
62       * Return the password.
63       */
64      public String getPassword() {
65  
66  	return (this.password);
67  
68      }
69  
70  
71      /***
72       * Set the password.
73       *
74       * @param password The new password
75       */
76      public void setPassword(String password) {
77  
78          this.password = password;
79  
80      }
81  
82  
83      /***
84       * Return the username.
85       */
86      public String getUsername() {
87  
88  	return (this.username);
89  
90      }
91  
92  
93      /***
94       * Set the username.
95       *
96       * @param username The new username
97       */
98      public void setUsername(String username) {
99  
100         this.username = username;
101 
102     }
103 
104 
105     // --------------------------------------------------------- Public Methods
106 
107 
108     /***
109      * Reset all properties to their default values.
110      *
111      * @param mapping The mapping used to select this instance
112      * @param request The servlet request we are processing
113      */
114     public void reset(ActionMapping mapping, HttpServletRequest request) {
115 
116         this.password = null;
117         this.username = null;
118 
119     }
120 
121 
122     /***
123      * Validate the properties that have been set from this HTTP request,
124      * and return an <code>ActionMessages</code> object that encapsulates any
125      * validation errors that have been found.  If no errors are found, return
126      * <code>null</code> or an <code>ActionMessages</code> object with no
127      * recorded error messages.
128      *
129      * @param mapping The mapping used to select this instance
130      * @param request The servlet request we are processing
131      */
132     public ActionErrors validate(ActionMapping mapping,
133                                  HttpServletRequest request) {
134 
135         ActionErrors errors = new ActionErrors();
136         if ((username == null) || (username.length() < 1))
137             errors.add("username", new ActionMessage("error.username.required"));
138         if ((password == null) || (password.length() < 1))
139             errors.add("password", new ActionMessage("error.password.required"));
140 
141         return errors;
142 
143     }
144 
145 
146 }