1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.struts.webapp.exercise;
21
22
23 import java.util.ArrayList;
24 import java.util.Collection;
25 import java.util.HashMap;
26 import java.util.List;
27 import java.util.Map;
28 import java.util.Vector;
29 import javax.servlet.http.HttpServletRequest;
30 import org.apache.struts.action.ActionForm;
31 import org.apache.struts.action.ActionMapping;
32 import org.apache.struts.util.LabelValueBean;
33
34
35 /***
36 * General purpose test bean for Struts custom tag tests.
37 *
38 * @version $Rev: 421488 $ $Date: 2006-07-12 20:43:08 -0700 (Wed, 12 Jul 2006) $
39 */
40
41 public class TestBean extends ActionForm {
42
43
44
45
46
47 /***
48 * A collection property where the elements of the collection are
49 * of type <code>LabelValueBean</code>.
50 */
51 private Collection beanCollection = null;
52
53 public Collection getBeanCollection() {
54 if (beanCollection == null) {
55 Vector entries = new Vector(10);
56
57 entries.add(new LabelValueBean("Label 0", "Value 0"));
58 entries.add(new LabelValueBean("Label 1", "Value 1"));
59 entries.add(new LabelValueBean("Label 2", "Value 2"));
60 entries.add(new LabelValueBean("Label 3", "Value 3"));
61 entries.add(new LabelValueBean("Label 4", "Value 4"));
62 entries.add(new LabelValueBean("Label 5", "Value 5"));
63 entries.add(new LabelValueBean("Label 6", "Value 6"));
64 entries.add(new LabelValueBean("Label 7", "Value 7"));
65 entries.add(new LabelValueBean("Label 8", "Value 8"));
66 entries.add(new LabelValueBean("Label 9", "Value 9"));
67
68 beanCollection = entries;
69 }
70
71 return (beanCollection);
72 }
73
74 public void setBeanCollection(Collection beanCollection) {
75 this.beanCollection = beanCollection;
76 }
77
78
79 /***
80 * A multiple-String SELECT element using a bean collection.
81 */
82 private String[] beanCollectionSelect = { "Value 1", "Value 3",
83 "Value 5" };
84
85 public String[] getBeanCollectionSelect() {
86 return (this.beanCollectionSelect);
87 }
88
89 public void setBeanCollectionSelect(String beanCollectionSelect[]) {
90 this.beanCollectionSelect = beanCollectionSelect;
91 }
92
93
94 /***
95 * A boolean property whose initial value is true.
96 */
97 private boolean booleanProperty = true;
98
99 public boolean getBooleanProperty() {
100 return (booleanProperty);
101 }
102
103 public void setBooleanProperty(boolean booleanProperty) {
104 this.booleanProperty = booleanProperty;
105 }
106
107
108 /***
109 * A multiple-String SELECT element using a collection.
110 */
111 private String[] collectionSelect = { "Value 2", "Value 4",
112 "Value 6" };
113
114 public String[] getCollectionSelect() {
115 return (this.collectionSelect);
116 }
117
118 public void setCollectionSelect(String collectionSelect[]) {
119 this.collectionSelect = collectionSelect;
120 }
121
122
123 /***
124 * A double property.
125 */
126 private double doubleProperty = 321.0;
127
128 public double getDoubleProperty() {
129 return (this.doubleProperty);
130 }
131
132 public void setDoubleProperty(double doubleProperty) {
133 this.doubleProperty = doubleProperty;
134 }
135
136
137 /***
138 * A boolean property whose initial value is false
139 */
140 private boolean falseProperty = false;
141
142 public boolean getFalseProperty() {
143 return (falseProperty);
144 }
145
146 public void setFalseProperty(boolean falseProperty) {
147 this.falseProperty = falseProperty;
148 }
149
150
151 /***
152 * A float property.
153 */
154 private float floatProperty = (float) 123.0;
155
156 public float getFloatProperty() {
157 return (this.floatProperty);
158 }
159
160 public void setFloatProperty(float floatProperty) {
161 this.floatProperty = floatProperty;
162 }
163
164
165 /***
166 * Integer arrays that are accessed as an array as well as indexed.
167 */
168 private int intArray[] = { 0, 10, 20, 30, 40 };
169
170 public int[] getIntArray() {
171 return (this.intArray);
172 }
173
174 public void setIntArray(int intArray[]) {
175 this.intArray = intArray;
176 }
177
178 private int intIndexed[] = { 0, 10, 20, 30, 40 };
179
180 public int getIntIndexed(int index) {
181 return (intIndexed[index]);
182 }
183
184 public void setIntIndexed(int index, int value) {
185 intIndexed[index] = value;
186 }
187
188
189 private int intMultibox[] = new int[0];
190
191 public int[] getIntMultibox() {
192 return (this.intMultibox);
193 }
194
195 public void setIntMultibox(int intMultibox[]) {
196 this.intMultibox = intMultibox;
197 }
198
199 /***
200 * An integer property.
201 */
202 private int intProperty = 123;
203
204 public int getIntProperty() {
205 return (this.intProperty);
206 }
207
208 public void setIntProperty(int intProperty) {
209 this.intProperty = intProperty;
210 }
211
212
213 /***
214 * A long property.
215 */
216 private long longProperty = 321;
217
218 public long getLongProperty() {
219 return (this.longProperty);
220 }
221
222 public void setLongProperty(long longProperty) {
223 this.longProperty = longProperty;
224 }
225
226
227 /***
228 * A multiple-String SELECT element.
229 */
230 private String[] multipleSelect = { "Multiple 3", "Multiple 5",
231 "Multiple 7" };
232
233 public String[] getMultipleSelect() {
234 return (this.multipleSelect);
235 }
236
237 public void setMultipleSelect(String multipleSelect[]) {
238 this.multipleSelect = multipleSelect;
239 }
240
241
242 /***
243 * A nested reference to another test bean (populated as needed).
244 */
245 private TestBean nested = null;
246
247 public TestBean getNested() {
248 if (nested == null)
249 nested = new TestBean();
250 return (nested);
251 }
252
253
254 /***
255 * A String property with an initial value of null.
256 */
257 private String nullProperty = null;
258
259 public String getNullProperty() {
260 return (this.nullProperty);
261 }
262
263 public void setNullProperty(String nullProperty) {
264 this.nullProperty = nullProperty;
265 }
266
267
268 /***
269 * A short property.
270 */
271 private short shortProperty = (short) 987;
272
273 public short getShortProperty() {
274 return (this.shortProperty);
275 }
276
277 public void setShortProperty(short shortProperty) {
278 this.shortProperty = shortProperty;
279 }
280
281
282 /***
283 * A single-String value for a SELECT element.
284 */
285 private String singleSelect = "Single 5";
286
287 public String getSingleSelect() {
288 return (this.singleSelect);
289 }
290
291 public void setSingleSelect(String singleSelect) {
292 this.singleSelect = singleSelect;
293 }
294
295
296 /***
297 * String arrays that are accessed as an array as well as indexed.
298 */
299 private String stringArray[] =
300 { "String 0", "String 1", "String 2", "String 3", "String 4" };
301
302 public String[] getStringArray() {
303 return (this.stringArray);
304 }
305
306 public void setStringArray(String stringArray[]) {
307 this.stringArray = stringArray;
308 }
309
310 private String stringIndexed[] =
311 { "String 0", "String 1", "String 2", "String 3", "String 4" };
312
313 public String getStringIndexed(int index) {
314 return (stringIndexed[index]);
315 }
316
317 public void setStringIndexed(int index, String value) {
318 stringIndexed[index] = value;
319 }
320
321
322 private String stringMultibox[] = new String[0];
323
324 public String[] getStringMultibox() {
325 return (this.stringMultibox);
326 }
327
328 public void setStringMultibox(String stringMultibox[]) {
329 this.stringMultibox = stringMultibox;
330 }
331
332 /***
333 * A String property.
334 */
335 private String stringProperty = "This is a string";
336
337 public String getStringProperty() {
338 return (this.stringProperty);
339 }
340
341 public void setStringProperty(String stringProperty) {
342 this.stringProperty = stringProperty;
343 }
344
345 /***
346 * An empty String property.
347 */
348 private String emptyStringProperty = "";
349
350 public String getEmptyStringProperty() {
351 return (this.emptyStringProperty);
352 }
353
354 public void setEmptyStringProperty(String emptyStringProperty) {
355 this.emptyStringProperty = emptyStringProperty;
356 }
357
358
359 /***
360 * A single-String value for a SELECT element based on resource strings.
361 */
362 private String resourcesSelect = "Resources 2";
363
364 public String getResourcesSelect() {
365 return (this.resourcesSelect);
366 }
367
368 public void setResourcesSelect(String resourcesSelect) {
369 this.resourcesSelect = resourcesSelect;
370 }
371
372
373 /***
374 * A property that allows a null value but is still used in a SELECT.
375 */
376 private String withNulls = null;
377
378 public String getWithNulls() {
379 return (this.withNulls);
380 }
381
382 public void setWithNulls(String withNulls) {
383 this.withNulls = withNulls;
384 }
385
386
387 /***
388 * A List property.
389 */
390 private List listProperty = null;
391
392 public List getListProperty() {
393 if (listProperty == null) {
394 listProperty = new ArrayList();
395 listProperty.add("dummy");
396 }
397 return listProperty;
398 }
399
400 public void setListProperty(List listProperty) {
401 this.listProperty = listProperty;
402 }
403
404 /***
405 * An empty List property.
406 */
407 private List emptyListProperty = null;
408
409 public List getEmptyListProperty() {
410 if (emptyListProperty == null) {
411 emptyListProperty = new ArrayList();
412 }
413 return emptyListProperty;
414 }
415
416 public void setEmptyListProperty(List emptyListProperty) {
417 this.emptyListProperty = emptyListProperty;
418 }
419
420
421 /***
422 * A Map property.
423 */
424 private Map mapProperty = null;
425
426 public Map getMapProperty() {
427 if (mapProperty == null) {
428 mapProperty = new HashMap();
429 mapProperty.put("dummy", "dummy");
430 }
431 return mapProperty;
432 }
433
434 public void setMapProperty(Map mapProperty) {
435 this.mapProperty = mapProperty;
436 }
437
438 /***
439 * An empty Map property.
440 */
441 private Map emptyMapProperty = null;
442
443 public Map getEmptyMapProperty() {
444 if (emptyMapProperty == null) {
445 emptyMapProperty = new HashMap();
446 }
447 return emptyMapProperty;
448 }
449
450 public void setEmptyMapProperty(Map emptyMapProperty) {
451 this.emptyMapProperty = emptyMapProperty;
452 }
453
454
455
456
457
458 /***
459 * Reset the properties that will be received as input.
460 */
461 public void reset(ActionMapping mapping, HttpServletRequest request) {
462
463 booleanProperty = false;
464 collectionSelect = new String[0];
465 intMultibox = new int[0];
466 multipleSelect = new String[0];
467 stringMultibox = new String[0];
468 if (nested != null)
469 nested.reset(mapping, request);
470
471 }
472
473
474 }