TD>
132 tr>
133 TABLE>
134 html: form>
135 body>
136 html: html>
137
138
Corresponding TestBean
Java code:
1
2
/ * 3 * $ header: /Home/cvs/jakarta-struts/src/examples/org/apache/tests/webapp/exercise/testbean.java ,v 1.4 2004/03/14 06:23:52 SRAEBURN EXP $ 4 * $ Revision: 1.4 $ 5 * $ DATE: 2004/03/14 06:23:52 $ 6 * 7 * Copyright 1999-2004 The Apache Software Foundation. 8 * 9 * licensed Under The Apache License, Version 2.0 (The " "); 10 * You may not use this file exceptin compliance with the license. 11 * You may obtain a copy of the license at 12 * 13 * http://www.apache.org/licenses/license-2.0 14 * 15 * Unless required by applicable law or agreed to in writing, software 16 * distributed under the License is distributed on an "AS IS" BASIS, 17 * WITHOUT WARRANTIES oR CONDITIONS OF ANY KIND, either express or implied. 18 * See the License for the specific language governing permissions and 19 * limiteds under the license. 20 * / 21
twenty two
twenty three
Package org.
Apache.
Struts.
WebApp.
EXERCISE;
twenty four
25
26
Import Java.
Util.
ArrayList;
27
Import Java.
Util.
COLLECTION;
Twist
Import Java.
Util.
Hashmap;
29
Import Java.
Util.
List;
30
Import Java.
Util.
Map;
31
Import Java.
Util.
Vector;
32
Import Javax.
servlet.
HTTP.
HTTPSERVLETREQUEST;
33
Import org.
Apache.
Struts.
Action.
Actionform;
34
Import org.
Apache.
Struts.
Action.
Actionmapping;
35
Import org.
Apache.
Struts.
Util.
Labelvaluebean;
36
37
38
/ ** 39 * General Purpose Test Bean for struts Custom Tag Tests. 40 * 41 * @version $ Revision: 1.4 $ $ DATE: 2004/03/14 06:23:52 $ 42 * /
43
44
public
Class testbean
Extends an actionform
{
...}
45
46
47
/ / -------------------------------------------------------------------------------------------- ------------- Properties
48
49
50
/ ** 51 * a Collection Property WHERE The Elements of the Collection Are 52 * of Type LabelValueBean code>. 53 * /
54
Private
Collection beancollection =
NULL;
55
56
public
Collection GetBeancollection
(
)
{
...}
57
IF
(beancollection ==
NULL
)
{
...}
58
Vector entries =
New
Vector
(
10
);
59
60 entries.
Add
(
New labelvaluebean
("
Label
0 "," Value
0 "
)
);
61 Entries.
Add
(
New labelvaluebean
("
Label
1 "," Value
1"
)
);
.
Add
(
New labelvaluebean
("
Label
2 "," Value
2"
)
);
.
Add
(
New labelvaluebean
("
Label
3 "," Value
3 "
)
);
STRIES.
Add
(
New labelvaluebean
("
Label
4 "," Value
4 "
)
);
65 entries.
Add
(
New labelvaluebean
("
Label
5 "," Value
5 "
)
);
.
Add
(
New labelvaluebean
("
Label
6 "," Value
6 "
)
);
.
Add
(
New labelvaluebean
("
Label
7 "," Value
7 "
)
);
.
Add
(
New labelvaluebean
("
Label
8 "," Value
8"
)
);
.
Add
(
New labelvaluebean
("
Label
9 "," Value
9"
)
);
70
7111;
72
}
73
74
Return
(Beancollection)
);
75
}
76
77
public
Void setBeancollection
(
Collection Beancollection
)
{
...}
78 THIS.
Beancollection = Beancollection;
79
}
80
81
82
/ ** 83 * a multiple-string select element useing a bean collection. 84 * / 85
Private
String
[
] beancollectionSelect =
{"Value
1 "," Value
3 ",
86 "Value
5 "
}
87
88
public
String
[
] GetBeancollectionSelect
(
)
{
...}
89
Return
.
BeancollectionSelect
);
90
}
91
92
public
Void setBeancollectionSelect
(
String beancollectionSelect
[
]
)
{
...}
93 this.
BeancollectionSelect = BeancollectionSelect;
94
}
95
96
97
/ ** 98 * a Boolean Property whose Initial value is true. 99 * /
100
Private
Boolean booleanproperty =
True;
101
102
public
Boolean getBooleanProperty
(
)
{
...}
103
Return
(BooleanProperty
);
104
}
105
106
public
Void setBooleanproperty
(
Boolean Booleanproperty
)
{
...}
THIS.
Booleanproperty = BooleanProperty;
108
}
109
110
111
/ ** 112 * a multiple-string select element sale a collection. 113 * /
114
Private
String
[
] CollectionSelect =
{"Value
2 "," Value
4 ",
115 "Value
6 "
}
116
117
public
String
[
] getCollectionSelect
(
)
{
...}
118
Return
.
Collectionselect
);
119
}
120
121
public
Void setCollectionSelect
(
String CollectionSelect
[
]
)
{
...}
122.
CollectionSelect = CollectionSelect;
123
}
124
125
126
/ ** 127 * a Double Property. 128 * /
129
Private
Double DoubleProperty =
321.
0;
130
131
public
Double getDoubleproperty
(
)
{
...}
132
Return
.
DoubleProperty
);
133
}
134
135
public
Void setDoubleproperty
Double DoubleProperty
)
{
...}
136 this.
DoubleProperty = doubleproperty;
137
}
138
139
140
/ ** 141 * a Boolean Property whose Initial value is false 142 * /
143
Private
Boolean FalseProperty =
False;
144
145
public
Boolean getfalseproperty
(
)
{
...}
146
Return
(FalseProperty
);
147
}
148
149
public
Void setfalseproperty
(
Boolean FalseProperty
)
{
...}
150 this.
FalseProperty = falseproperty;
151
}
152
153
154
/ ** 155 * a float proty. 156 * /
157
Private float floatproperty =
(Float)
)
123.
0;
158
159
Public Float getFloatProperty
(
)
{
...}
160
Return
.
FloatProperty
);
161
}
162
163
public
Void setFloatProperty
(Float FloatProperty
)
{
...}
THIS.
FLOATPROPERTY = floatproperty;
165
}
166
167
168
/ ** 169 * Integer Arrays That Are Accessed as an Array As Well as Indexed. 170 * /
171
Private
Int IntaRray
[
] =
{
0,
10,
20,
30,
40
}
172
173
public
int
[
] GetInTarray
(
)
{
...}
174
Return
.
IntaRray
);
175
}
176
177
public
Void SetInTarray
(
Int IntaRray
[
]
)
{
...}
178 this.
INTARRAY = INTARRAY;
179
}
180
181
Private
Int intindexed
[
] =
{
0,
10,
20,
30,
40
}
182
183
public
Int getIntIndexed
(
Int index
)
{
...}
184
Return
(intIndexed)
[index
]
);
185
}
186
187
public
Void setInTindexed
(
Int index,
Int Value
)
{
...}
188 INTINDEXED
[index
] = Value;
189
}
190
191
192
Private
Int IntMultiBox
[
] =
New
int
[
0
];
193
194
public
int
[
] GetInTmultiBox
(
)
{
...}
195
Return
(this.IntMultiBox
);
196
}
197
198
public
Void setInTmultiBox
(
Int IntMultiBox
[
]
)
{
...}
199 THIS.
INTMULTIBOX = INTMULTIBOX;
200
}
201
202
/ ** 203 * an in turner property. 204 * /
205
Private
INT INTPROPERTY =
123;
206
207
public
Int getIntproperty
(
)
{
...}
208
Return
.
INTPROPERTY
);
209
}
210
211
public
Void setInTproperty
(
Int Intproperty
)
{
...}
THIS.
INTPROPERTY = INTPROPERTY;
213
}
214
215
216
/ ** 217 * a long proty. 218 * /
219
PRIVATE long longproperty =
321;
220
221
Public Long GetlongProperty
(
)
{
...}
222
Return
.
Longproperty
);
223
}
224
225
public
Void setlongproperty
(long longproperty)
)
{
...}
THIS.
Longproperty = longproperty;
227
}
228
229
230
/ ** 231 * a multiple-string select element. 232 * /
233
Private
String
[
] Multipleselect =
{"Multiple
3 "," Multiple
5 ",
234 "Multiple
7 "
}
235
236
public
String
[
] getMultiPleselect
(
)
{
...}
237
Return
.
MultiPleSelect
);
238
}
239
240
public
Void setMultiPleselect
(
String Multipleselect
[
]
)
{
...}
THIS.
Multipleselect = MultipleElectr;
242
}
243
244
245
/ ** 246 * a Nested Reference to another test bean (populate as needed). 247 * /
248
Private TestBean Nested =
NULL;
249
250
Public TestBean GetNested
(
)
{
...}
251
IF
(nested ==
NULL
)
252 nested =
New TestBean
(
);
253
Return
(Nested)
);
254
}
255
256
257
/ ** 258 * a String Property with an initial value of null. 259 * / 260
Private
String nullproperty =
NULL;
261
262
public
String getnullproperty
(
)
{
...}
263
Return
.
NullProperty
);
264
}
265
266
public
Void SetNullProperty
(
String Nullproperty
)
{
...}
267 this.
nullproperty = nullproperty;
268
}
269
270
271
/ ** 272 * a short property. 273 * /
274
Private Short shortproperty =
(Short)
)
987;
275
276
Public Short GetshortProperty
(
)
{
...}
277
Return
.
Shortproperty
);
278
}
279
280
public
Void setshortproperty
(Short shortproperty
)
{
...}
THIS.
Shortproperty = shortproperty;
282
}
283
284
285
/ ** 286 * a Single-string value for a select element. 287 * /
288
Private
STRING SINGLESELECT = "SINGLE
5 ";
289
290
public
String getsingleselect
(
)
{
...}
291
Return
.
Singleselect
);
292
}
293
294
public
Void setsingleselect
(
String SingleselectElectr
)
{
...}
THIS.
SINGLESELECT = SINGLESELECT;
296
}
297
298
299
/ ** 300 * String Arrays That Are Accessed as an Array As Well as Indexed. 301 * /
302
Private
String StringArray
[
] =
303
{"
String
0 ","
String
1", "
String
2", "
String
3 ","
String
4 "
}
304
305
public
String
[
] GetStringArray
(
)
{
...}
306
Return
.
StringArray
);
307
}
308
309
public
Void setStringArray
(
String StringArray
[
]
)
{
...}
310 THIS.
StringArray = StringArray;
311
}
312
313
Private
String stringIndexed
[
] =
314
{"
String
0 ","
String
1 "," String
2", "
String
3 ","
String
4 "
}
315
316
public
String getStringIndexed
(
Int index
)
{
...}
317
Return
(StringIndexed)
[index
]
);
318
}
319
320
public
Void setStringIndexed
(
Int index,
String Value
)
{
...}
321 StringIndexed
[index
] = Value;
322
}
323
324
325
Private
String StringMultiBox
[
] =
New
String
[
0
];
326
327
public
String
[
] GetStringMultiBox
(
)
{
...}
328
Return
.
StringMultiBox
);
329
}
330
331
public
Void SetStringMultiBox
(
String StringMultiBox
[
]
)
{
...}
332 this.
Stringmultibox = stringmultibox;
333
}
334
335
/ ** 336 * a string property. 337 * /
338
Private
String StringProperty = "this is a string";
339
340
public
String GetStringProperty
(
)
{
...}
341
Return
.
StringProperty
);
342
}
343
344
public
Void setStringProperty
(
String StringProperty
)
{
...}
345 this.
StringProperty = StringProperty;
346
}
347
348
/ ** 349 * an Empty string property. 350 * /
351
Private
String emptystringproperty = "";
352
353
public
String getEmptystringProperty
(
)
{
...}
354
Return
.
EMPTYSTRINGPROPERTY
);
355
}
356
357
public
Void SeteemptystringProperty
(
String EmptyStringProperty
)
{
...}
358 this.
EmptystringProperty = EmptystringProperty;
359
}
360
361
362
/ ** 363 * a SINGLE-STRING VALUE for a Select Element Based on Resource Strings. 364 * /
365
Private
String resourceesselect = "resources
2";
366
367
public
String getResourcesSselectelect
(
)
{
...}
368
Return
.
ResourcesSselect);
369
}
370
371
public
Void setResourcesSselectelect
(
String ResourcesSselectElect
)
{
...}
THIS.
Resourcesselect = resource;
373
}
374
375
376
/ ** 377 * a Property That Allows a Null Value But is stock used in a select. 378 * /
379
Private
String withnulls =
NULL;
380
381
public
String getwithnulls
(
)
{
...}
382
Return
.
Withnulls
);
383
}
384
385
public
Void setwithnulls
(
String withnulls
)
{
...}
386 this.
Withnulls = WithnUlls;
387
}
388
389
390
/ ** 391 * a List property. 392 * /
393
Private
List ListProperty =
NULL;
394
395
public
List getListProperty
(
)
{
...}
396
IF
(ListProperty ==
NULL
)
{
...}
397 ListProperty =
New
ArrayList
(
);
398 ListProperty.
Add
("Dummy"
);
399
}
400
Return ListProperty;
401
}
402
403
public
Void setListProperty
(
List ListProperty
)
{
...}
404 this.
ListProperty = listproperty;
405
}
406
407
/ ** 408 * an Empty List Property. 409 * /
410
Private
List emptyListproperty =
NULL;
411
412
public
List getemptylistproperty
(
)
{
...}
413
IF
(EmptyListProperty ==
NULL
)
{
...}
414 EMPTYLISTPROPERTY =
New
ArrayList
(
);
415
}
416
Return EmptyListProperty;
417
}
418
419
public
Void setEmptyListProperty
(
List EmptyListProperty
)
{
...}
420 this.
EmptyListProperty = EmptyListProperty;
421
}
422
423
424
/ ** 425 * a Map property. 426 * /
427
Private
Map mapproperty =
NULL;
428
429
public
Map getMAPPROPERTY
(
)
{
...}
430
IF
(mapproperty == NULL
)
{
...}
431 mapproperty =
New
Hashmap
(
);
432 MAPPROPERTY.
PUT
("Dummy", "DUMMY"
);
433
}
434
Return mapproperty;
435
}
436
437
public
Void SetMApproperty
(
Map mapproperty
)
{
...}
438 this.
MAPPROPERTY = MAPPROPERTY;
439
}
440
441
/ ** 442 * an Empty map Property. 443 * /
444
Private
Map EmptyMApproperty =
NULL;
445
446
public
Map getemptymappproperty
(
)
{
...}
447
IF
(EmptyMApproperty ==
NULL
)
{
...}
448 EMPTYMAPPROPERTY =
New
Hashmap
(
);
449
}
450
Return EmptyMapproperty;
451
}
452
453
public
Void setemptyMApproperty
(
Map EmptyMApproperty
)
{
...}
THIS.
EmptyMappproperty = EmptyMappProperty;
455
}
456
457
458
/ / -------------------------------------------------------------------------------------------- --------- Public Methods
459
460
461
/ ** 462 * RESET The Properties That Will Be Received As Input. 463 * /
464
public
Void RESET
(ActionMapping Mapping, HttpServletRequest Request
)
{
...}
465
466 BooleanProperty =
False;
467 CollectionSelect =
New
String
[
0
];
468 INTMULTIBOX =
New
int
[
0
];
469 MULTIPLESELECT =
New
String
[
0
];
470 stringmultiBox =
New
String
[
0
];
471
IF
(Nested! =
NULL
)
472 nested.
RESET
(Mapping, REQUEST
);
473
474
}
475
476
477
}
478
转载请注明原文地址:https://www.9cbs.com/read-113260.html