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 package examples.simple;
23
24 import jakarta.servlet.http.HttpServletRequest;
25
26 import org.apache.struts.action.ActionErrors;
27 import org.apache.struts.action.ActionForm;
28 import org.apache.struts.action.ActionMapping;
29 import org.apache.struts.action.ActionMessage;
30
31 /**
32 * A simple ActionForm
33 *
34 * @version $Rev$ $Date$
35 */
36 public class SimpleActionForm extends ActionForm {
37 private static final long serialVersionUID = 4189849944389346127L;
38
39 // ------------------------------------------------------ Instance Variables
40
41 /** Name */
42 private String name = null;
43
44 /** Secret */
45 private String secret = null;
46
47 /** Color */
48 private String color = null;
49
50 /** Confirm */
51 private boolean confirm = false;
52
53 /** Rating */
54 private String rating = null;
55
56 /** Message */
57 private String message = null;
58
59 /** Hidden */
60 private String hidden = null;
61
62 // ------------------------------------------------------------ Constructors
63
64 /**
65 * Constructor for MultiboxActionForm.
66 */
67 public SimpleActionForm() {
68 super();
69 }
70
71 // ---------------------------------------------------------- Public Methods
72
73 /**
74 * Reset all properties to their default values.
75 *
76 * @param mapping The mapping used to select this instance
77 * @param request The servlet request we are processing
78 */
79 public void reset(ActionMapping mapping, HttpServletRequest request) {
80
81 this.name = null;
82 this.secret = null;
83 this.color = null;
84 this.confirm = false;
85 this.rating = null;
86 this.message = null;
87 this.hidden = null;
88
89 }
90
91 /**
92 * Validate the properties that have been set from this HTTP request,
93 * and return an <code>ActionMessages</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>ActionMessages</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 * @return ActionMessages if any validation errors occurred
102 */
103 public ActionErrors validate(
104 ActionMapping mapping,
105 HttpServletRequest request) {
106
107 ActionErrors errors = new ActionErrors();
108
109 // Name must be entered
110 if ((name == null) || (name.length() < 1)) {
111 errors.add("name", new ActionMessage("errors.name.required"));
112 }
113
114 // Secret Phrase must be entered
115 if ((secret == null) || (secret.length() < 1)) {
116 errors.add("secret", new ActionMessage("errors.secret.required"));
117 }
118
119 return (errors);
120
121 }
122
123 // -------------------------------------------------------------- Properties
124
125 /**
126 * Returns the color.
127 * @return String
128 */
129 public String getColor() {
130 return color;
131 }
132
133 /**
134 * Returns the confirm.
135 * @return boolean
136 */
137 public boolean getConfirm() {
138 return confirm;
139 }
140
141 /**
142 * Returns the hidden.
143 * @return String
144 */
145 public String getHidden() {
146 return hidden;
147 }
148
149 /**
150 * Returns the message.
151 * @return String
152 */
153 public String getMessage() {
154 return message;
155 }
156
157 /**
158 * Returns the name.
159 * @return String
160 */
161 public String getName() {
162 return name;
163 }
164
165 /**
166 * Returns the rating.
167 * @return String
168 */
169 public String getRating() {
170 return rating;
171 }
172
173 /**
174 * Returns the secret.
175 * @return String
176 */
177 public String getSecret() {
178 return secret;
179 }
180
181 /**
182 * Sets the color.
183 * @param color The color to set
184 */
185 public void setColor(String color) {
186 this.color = color;
187 }
188
189 /**
190 * Sets the confirm.
191 * @param confirm The confirm to set
192 */
193 public void setConfirm(boolean confirm) {
194 this.confirm = confirm;
195 }
196
197 /**
198 * Sets the hidden.
199 * @param hidden The hidden to set
200 */
201 public void setHidden(String hidden) {
202 this.hidden = hidden;
203 }
204
205 /**
206 * Sets the message.
207 * @param message The message to set
208 */
209 public void setMessage(String message) {
210 this.message = message;
211 }
212
213 /**
214 * Sets the name.
215 * @param name The name to set
216 */
217 public void setName(String name) {
218 this.name = name;
219 }
220
221 /**
222 * Sets the rating.
223 * @param rating The rating to set
224 */
225 public void setRating(String rating) {
226 this.rating = rating;
227 }
228
229 /**
230 * Sets the secret.
231 * @param secret The secret to set
232 */
233 public void setSecret(String secret) {
234 this.secret = secret;
235 }
236
237 }