2
* $Header: /home/cvs/jakarta-struts/contrib/struts-el/src/exercise-taglib/org/apache/struts/webapp/exercise/TestBean.java,v 1.3 2004/03/14 07:15:06 sraeburn Exp $
4
* $Date: 2004/03/14 07:15:06 $
6
* Copyright 1999-2004 The Apache Software Foundation.
8
* Licensed under the Apache License, Version 2.0 (the "License");
9
* you may not use this file except in compliance with the License.
10
* You may obtain a copy of the License at
12
* http://www.apache.org/licenses/LICENSE-2.0
14
* Unless required by applicable law or agreed to in writing, software
15
* distributed under the License is distributed on an "AS IS" BASIS,
16
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
* See the License for the specific language governing permissions and
18
* limitations under the License.
22
package org.apache.struts.webapp.exercise;
25
import java.util.Collection;
26
import java.util.Vector;
27
import javax.servlet.http.HttpServletRequest;
28
import org.apache.struts.action.ActionForm;
29
import org.apache.struts.action.ActionMapping;
30
import org.apache.struts.util.LabelValueBean;
34
* General purpose test bean for Struts custom tag tests.
36
* @author Craig R. McClanahan
37
* @author Martin F N Cooper
38
* @version $Revision: 1.3 $ $Date: 2004/03/14 07:15:06 $
41
public class TestBean extends ActionForm {
44
// ------------------------------------------------------------- Properties
48
* A collection property where the elements of the collection are
49
* of type <code>LabelValueBean</code>.
51
private Collection beanCollection = null;
53
public Collection getBeanCollection() {
54
if (beanCollection == null) {
55
Vector entries = new Vector(10);
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"));
68
beanCollection = entries;
71
return (beanCollection);
74
public void setBeanCollection(Collection beanCollection) {
75
this.beanCollection = beanCollection;
80
* A multiple-String SELECT element using a bean collection.
82
private String[] beanCollectionSelect = { "Value 1", "Value 3",
85
public String[] getBeanCollectionSelect() {
86
return (this.beanCollectionSelect);
89
public void setBeanCollectionSelect(String beanCollectionSelect[]) {
90
this.beanCollectionSelect = beanCollectionSelect;
95
* A boolean property whose initial value is true.
97
private boolean booleanProperty = true;
99
public boolean getBooleanProperty() {
100
return (booleanProperty);
103
public void setBooleanProperty(boolean booleanProperty) {
104
this.booleanProperty = booleanProperty;
109
* A multiple-String SELECT element using a collection.
111
private String[] collectionSelect = { "Value 2", "Value 4",
114
public String[] getCollectionSelect() {
115
return (this.collectionSelect);
118
public void setCollectionSelect(String collectionSelect[]) {
119
this.collectionSelect = collectionSelect;
126
private double doubleProperty = 321.0;
128
public double getDoubleProperty() {
129
return (this.doubleProperty);
132
public void setDoubleProperty(double doubleProperty) {
133
this.doubleProperty = doubleProperty;
138
* A boolean property whose initial value is false
140
private boolean falseProperty = false;
142
public boolean getFalseProperty() {
143
return (falseProperty);
146
public void setFalseProperty(boolean falseProperty) {
147
this.falseProperty = falseProperty;
154
private float floatProperty = (float) 123.0;
156
public float getFloatProperty() {
157
return (this.floatProperty);
160
public void setFloatProperty(float floatProperty) {
161
this.floatProperty = floatProperty;
166
* Integer arrays that are accessed as an array as well as indexed.
168
private int intArray[] = { 0, 10, 20, 30, 40 };
170
public int[] getIntArray() {
171
return (this.intArray);
174
public void setIntArray(int intArray[]) {
175
this.intArray = intArray;
178
private int intIndexed[] = { 0, 10, 20, 30, 40 };
180
public int getIntIndexed(int index) {
181
return (intIndexed[index]);
184
public void setIntIndexed(int index, int value) {
185
intIndexed[index] = value;
189
private int intMultibox[] = new int[0];
191
public int[] getIntMultibox() {
192
return (this.intMultibox);
195
public void setIntMultibox(int intMultibox[]) {
196
this.intMultibox = intMultibox;
200
* An integer property.
202
private int intProperty = 123;
204
public int getIntProperty() {
205
return (this.intProperty);
208
public void setIntProperty(int intProperty) {
209
this.intProperty = intProperty;
216
private long longProperty = 321;
218
public long getLongProperty() {
219
return (this.longProperty);
222
public void setLongProperty(long longProperty) {
223
this.longProperty = longProperty;
228
* A multiple-String SELECT element.
230
private String[] multipleSelect = { "Multiple 3", "Multiple 5",
233
public String[] getMultipleSelect() {
234
return (this.multipleSelect);
237
public void setMultipleSelect(String multipleSelect[]) {
238
this.multipleSelect = multipleSelect;
243
* A nested reference to another test bean (populated as needed).
245
private TestBean nested = null;
247
public TestBean getNested() {
249
nested = new TestBean();
255
* A String property with an initial value of null.
257
private String nullProperty = null;
259
public String getNullProperty() {
260
return (this.nullProperty);
263
public void setNullProperty(String nullProperty) {
264
this.nullProperty = nullProperty;
271
private short shortProperty = (short) 987;
273
public short getShortProperty() {
274
return (this.shortProperty);
277
public void setShortProperty(short shortProperty) {
278
this.shortProperty = shortProperty;
283
* A single-String value for a SELECT element.
285
private String singleSelect = "Single 5";
287
public String getSingleSelect() {
288
return (this.singleSelect);
291
public void setSingleSelect(String singleSelect) {
292
this.singleSelect = singleSelect;
297
* String arrays that are accessed as an array as well as indexed.
299
private String stringArray[] =
300
{ "String 0", "String 1", "String 2", "String 3", "String 4" };
302
public String[] getStringArray() {
303
return (this.stringArray);
306
public void setStringArray(String stringArray[]) {
307
this.stringArray = stringArray;
310
private String stringIndexed[] =
311
{ "String 0", "String 1", "String 2", "String 3", "String 4" };
313
public String getStringIndexed(int index) {
314
return (stringIndexed[index]);
317
public void setStringIndexed(int index, String value) {
318
stringIndexed[index] = value;
321
private String indexedStrings[] =
322
{ "alpha", "beta", "gamma", "delta", "epsilon" };
324
public String[] getIndexedStrings()
326
return (indexedStrings);
329
private String stringMultibox[] = new String[0];
331
public String[] getStringMultibox() {
332
return (this.stringMultibox);
335
public void setStringMultibox(String stringMultibox[]) {
336
this.stringMultibox = stringMultibox;
342
private String stringProperty = "This is a string";
344
public String getStringProperty() {
345
return (this.stringProperty);
348
public void setStringProperty(String stringProperty) {
349
this.stringProperty = stringProperty;
353
* An empty String property.
355
private String emptyStringProperty = "";
357
public String getEmptyStringProperty() {
358
return (this.emptyStringProperty);
361
public void setEmptyStringProperty(String emptyStringProperty) {
362
this.emptyStringProperty = emptyStringProperty;
366
* A list of coordinate objects.
368
private Coord[] coords =
369
{ new Coord(0, 0), new Coord(0, 1), new Coord(1, 1), new Coord(2, 0),
373
public Coord[] getCoords() { return (coords); }
375
public Coord getCoord(int index) { return (coords[index]); }
377
public void setCoord(int index, Coord coord) { coords[index] = coord; }
382
public String images[] = {"T1.gif", "T2.gif"};
384
public String[] getImages() { return (images); }
386
private Coord[] imageCoords = { new Coord(0, 0), new Coord(0, 0) };
388
public Coord[] getImageCoords() { return (imageCoords); }
390
public Coord getImageCoord(int index) { return (imageCoords[index]); }
392
public void setImageCoord(int index, Coord coord)
393
{ imageCoords[index] = coord; }
396
* A property that allows a null value but is still used in a SELECT.
398
private String withNulls = null;
400
public String getWithNulls() {
401
return (this.withNulls);
404
public void setWithNulls(String withNulls) {
405
this.withNulls = withNulls;
409
// --------------------------------------------------------- Public Methods
413
* Reset the properties that will be received as input.
415
public void reset(ActionMapping mapping, HttpServletRequest request) {
417
booleanProperty = false;
418
collectionSelect = new String[0];
419
intMultibox = new int[0];
420
multipleSelect = new String[0];
421
stringMultibox = new String[0];
423
nested.reset(mapping, request);