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.multibox;
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
30 /**
31 * An ActionForm for the Multibox examples
32 *
33 * @version $Rev$ $Date$
34 */
35 public class MultiboxActionForm extends ActionForm {
36 private static final long serialVersionUID = -7784260148584459143L;
37
38 // ------------------------------------------------------ Instance Variables
39
40 /** Fruits */
41 private String[] fruits = {};
42
43 /** Colors */
44 private String[] colors = {};
45
46 // ------------------------------------------------------------ Constructors
47
48 /**
49 * Constructor for MultiboxActionForm.
50 */
51 public MultiboxActionForm() {
52 super();
53 }
54
55 // ---------------------------------------------------------- Public Methods
56
57 /**
58 * Clear all checkboxes
59 *
60 * @param mapping The mapping used to select this instance
61 * @param request The servlet request we are processing
62 */
63 public void reset(ActionMapping mapping, HttpServletRequest request) {
64
65 /*
66 * The ActionForm reset method should only be used to *clear*
67 * checkboxes. The correct place to *set* default checkbox values is in
68 * the 'prepare' action, called prior to displaying the form page.
69 */
70 String[] empty = {};
71 this.fruits = empty;
72 this.colors = empty;
73
74 }
75
76 /**
77 * Validate the properties that have been set from this HTTP request,
78 * and return an <code>ActionMessages</code> object that encapsulates any
79 * validation errors that have been found. If no errors are found, return
80 * <code>null</code> or an <code>ActionMessages</code> object with no
81 * recorded error messages.
82 *
83 * @param mapping The mapping used to select this instance
84 * @param request The servlet request we are processing
85 *
86 * @return ActionMessages if any validation errors occurred
87 */
88 public ActionErrors validate(
89 ActionMapping mapping,
90 HttpServletRequest request) {
91
92 /*
93 * We're not doing any validation (yet) so return null to
94 * indicate that there were no errors. (We don't
95 * actually need to override this nethod unles we're doing
96 * validation - but it's here for reference)
97 */
98 return null;
99 }
100
101 // -------------------------------------------------------------- Properties
102
103 /**
104 * Returns the colors.
105 * @return String[]
106 */
107 public String[] getColors() {
108 return colors;
109 }
110
111 /**
112 * Returns the fruits.
113 * @return String[]
114 */
115 public String[] getFruits() {
116 return fruits;
117 }
118
119 /**
120 * Sets the colors.
121 * @param colors The colors to set
122 */
123 public void setColors(String[] colors) {
124 this.colors = colors;
125 }
126
127 /**
128 * Sets the fruits.
129 * @param fruits The fruits to set
130 */
131 public void setFruits(String[] fruits) {
132 this.fruits = fruits;
133 }
134
135 }