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