001: /*
002: * $Id: SimpleActionForm.java 471754 2006-11-06 14:55:09Z husted $
003: *
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021:
022: package examples.simple;
023:
024: import javax.servlet.http.HttpServletRequest;
025:
026: import org.apache.struts.action.ActionErrors;
027: import org.apache.struts.action.ActionForm;
028: import org.apache.struts.action.ActionMapping;
029: import org.apache.struts.action.ActionMessage;
030:
031: /**
032: * A simple ActionForm
033: *
034: * @version $Rev: 471754 $ $Date: 2006-11-06 08:55:09 -0600 (Mon, 06 Nov 2006) $
035: */
036: public class SimpleActionForm extends ActionForm {
037:
038: // ------------------------------------------------------ Instance Variables
039:
040: /** Name */
041: private String name = null;
042:
043: /** Secret */
044: private String secret = null;
045:
046: /** Color */
047: private String color = null;
048:
049: /** Confirm */
050: private boolean confirm = false;
051:
052: /** Rating */
053: private String rating = null;
054:
055: /** Message */
056: private String message = null;
057:
058: /** Hidden */
059: private String hidden = null;
060:
061: // ------------------------------------------------------------ Constructors
062:
063: /**
064: * Constructor for MultiboxActionForm.
065: */
066: public SimpleActionForm() {
067: super ();
068: }
069:
070: // ---------------------------------------------------------- Public Methods
071:
072: /**
073: * Reset all properties to their default values.
074: *
075: * @param mapping The mapping used to select this instance
076: * @param request The servlet request we are processing
077: */
078: public void reset(ActionMapping mapping, HttpServletRequest request) {
079:
080: this .name = null;
081: this .secret = null;
082: this .color = null;
083: this .confirm = false;
084: this .rating = null;
085: this .message = null;
086: this .hidden = null;
087:
088: }
089:
090: /**
091: * Validate the properties that have been set from this HTTP request,
092: * and return an <code>ActionMessages</code> object that encapsulates any
093: * validation errors that have been found. If no errors are found, return
094: * <code>null</code> or an <code>ActionMessages</code> object with no
095: * recorded error messages.
096: *
097: * @param mapping The mapping used to select this instance
098: * @param request The servlet request we are processing
099: *
100: * @return ActionMessages if any validation errors occurred
101: */
102: public ActionErrors validate(ActionMapping mapping,
103: HttpServletRequest request) {
104:
105: ActionErrors errors = new ActionErrors();
106:
107: // Name must be entered
108: if ((name == null) || (name.length() < 1)) {
109: errors.add("name",
110: new ActionMessage("errors.name.required"));
111: }
112:
113: // Secret Phrase must be entered
114: if ((secret == null) || (secret.length() < 1)) {
115: errors.add("secret", new ActionMessage(
116: "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: }
|