質問編集履歴

1

追記

2020/10/24 13:46

投稿

Y.Mamoru
Y.Mamoru

スコア47

test CHANGED
File without changes
test CHANGED
@@ -13,3 +13,635 @@
13
13
 
14
14
 
15
15
  初歩的な質問だとは思うのですが、アドバイスをお願いします。
16
+
17
+
18
+
19
+ ※UserActionFormはsetter,getterクラス。LoopListFormはListを、別のListに格納するクラスです。
20
+
21
+ ```UserActionForm
22
+
23
+ package model;
24
+
25
+
26
+
27
+ import java.sql.Date;
28
+
29
+ import java.sql.Timestamp;
30
+
31
+
32
+
33
+ import org.apache.struts.action.ActionForm;
34
+
35
+
36
+
37
+ public class UserActionForm extends ActionForm {
38
+
39
+
40
+
41
+ private String userID;
42
+
43
+ private String password;
44
+
45
+ private String auth;
46
+
47
+ private String sectionID;
48
+
49
+ private String name;
50
+
51
+ private String birthyear;
52
+
53
+ private String birthmonth;
54
+
55
+ private String birthdate;
56
+
57
+ private String birthday;
58
+
59
+ private String sex;
60
+
61
+ private String address;
62
+
63
+ private String mail;
64
+
65
+ private String qual;
66
+
67
+ private Date createDate;
68
+
69
+ private String createUser;
70
+
71
+ private Date Date;
72
+
73
+ private String updateUser;
74
+
75
+ private String invalidFlag;
76
+
77
+ private String hiddenID;
78
+
79
+ private String action;
80
+
81
+ private String attendance;
82
+
83
+ private Timestamp time;
84
+
85
+ private int workTime;
86
+
87
+ private int overTime;
88
+
89
+ private int earlyCount;
90
+
91
+ private int lateCount;
92
+
93
+ private int works;
94
+
95
+ private int Hour;
96
+
97
+ private int Minutes;
98
+
99
+
100
+
101
+ public int getEarlyCount() {
102
+
103
+ return earlyCount;
104
+
105
+ }
106
+
107
+ public void setEarlyCount(int earlyCount) {
108
+
109
+ this.earlyCount = earlyCount;
110
+
111
+ }
112
+
113
+ public int getLateCount() {
114
+
115
+ return lateCount;
116
+
117
+ }
118
+
119
+ public void setLateCount(int lateCount) {
120
+
121
+ this.lateCount = lateCount;
122
+
123
+ }
124
+
125
+ public int getOverTime() {
126
+
127
+ return overTime;
128
+
129
+ }
130
+
131
+ public void setOverTime(int overTime) {
132
+
133
+ this.overTime = overTime;
134
+
135
+ }
136
+
137
+ public int getHour() {
138
+
139
+ return Hour;
140
+
141
+ }
142
+
143
+ public void setHour(int Hour) {
144
+
145
+ this.Hour = Hour;
146
+
147
+ }
148
+
149
+
150
+
151
+ public int getMinutes() {
152
+
153
+ return Minutes;
154
+
155
+ }
156
+
157
+ public void setMinutes(int Minutes) {
158
+
159
+ this.Minutes = Minutes;
160
+
161
+ }
162
+
163
+
164
+
165
+ public int getWorks() {
166
+
167
+ return works;
168
+
169
+ }
170
+
171
+ public void setWorks(int works) {
172
+
173
+ this.works = works;
174
+
175
+ }
176
+
177
+
178
+
179
+ public int getWorkTime() {
180
+
181
+ return workTime;
182
+
183
+ }
184
+
185
+ public void setWorkTime(int workTime) {
186
+
187
+ this.workTime = workTime;
188
+
189
+ }
190
+
191
+
192
+
193
+ public Timestamp getTime() {
194
+
195
+ return time;
196
+
197
+ }
198
+
199
+ public void setTime(Timestamp time) {
200
+
201
+ this.time = time;
202
+
203
+ }
204
+
205
+
206
+
207
+ public String getAttendance() {
208
+
209
+ return attendance;
210
+
211
+ }
212
+
213
+ public void setAttendance(String attendance) {
214
+
215
+ this.attendance = attendance;
216
+
217
+ }
218
+
219
+
220
+
221
+ public String getAction() {
222
+
223
+ return action;
224
+
225
+ }
226
+
227
+ public void setAction(String action) {
228
+
229
+ this.action = action;
230
+
231
+ }
232
+
233
+
234
+
235
+ public String getHiddenID() {
236
+
237
+ return hiddenID;
238
+
239
+ }
240
+
241
+ public void setHiddenID(String hiddenID) {
242
+
243
+ this.hiddenID = hiddenID;
244
+
245
+ }
246
+
247
+
248
+
249
+ public String getUserID() {
250
+
251
+ return userID;
252
+
253
+ }
254
+
255
+ public void setUserID(String userID) {
256
+
257
+ this.userID = userID;
258
+
259
+ }
260
+
261
+
262
+
263
+ public String getPassword() {
264
+
265
+ return password;
266
+
267
+ }
268
+
269
+ public void setPassword(String password) {
270
+
271
+ this.password = password;
272
+
273
+ }
274
+
275
+
276
+
277
+ public String getName() {
278
+
279
+ return name;
280
+
281
+ }
282
+
283
+ public void setName(String name) {
284
+
285
+ this.name = name;
286
+
287
+ }
288
+
289
+
290
+
291
+ public String getBirthyear() {
292
+
293
+ return birthyear;
294
+
295
+ }
296
+
297
+ public void setBirthyear(String birthyear) {
298
+
299
+ this.birthyear = birthyear;
300
+
301
+ }
302
+
303
+
304
+
305
+ public String getBirthmonth() {
306
+
307
+ return birthmonth;
308
+
309
+ }
310
+
311
+ public void setBirthmonth(String birthmonth) {
312
+
313
+ this.birthmonth = birthmonth;
314
+
315
+ }
316
+
317
+
318
+
319
+ public String getBirthdate() {
320
+
321
+ return birthdate;
322
+
323
+ }
324
+
325
+ public void setBirthdate(String birthdate) {
326
+
327
+ this.birthdate = birthdate;
328
+
329
+ }
330
+
331
+
332
+
333
+ public String getBirthday() {
334
+
335
+ return birthday;
336
+
337
+ }
338
+
339
+ public void setBirthday(String birthday) {
340
+
341
+ this.birthday = birthday;
342
+
343
+ }
344
+
345
+
346
+
347
+ public String getSex() {
348
+
349
+ return sex;
350
+
351
+ }
352
+
353
+ public void setSex(String sex) {
354
+
355
+ this.sex = sex;
356
+
357
+ }
358
+
359
+
360
+
361
+ public String getMail() {
362
+
363
+ return mail;
364
+
365
+ }
366
+
367
+ public void setMail(String mail) {
368
+
369
+ this.mail = mail;
370
+
371
+ }
372
+
373
+
374
+
375
+ public Date getCreateDate() {
376
+
377
+ return createDate;
378
+
379
+ }
380
+
381
+ public void setCreateDate(Date createDate) {
382
+
383
+ this.createDate = createDate;
384
+
385
+ }
386
+
387
+
388
+
389
+ public Date getDate() {
390
+
391
+ return Date;
392
+
393
+ }
394
+
395
+ public void setDate(Date Date) {
396
+
397
+ this.Date = Date;
398
+
399
+ }
400
+
401
+
402
+
403
+ public String getAuth() {
404
+
405
+ return auth;
406
+
407
+ }
408
+
409
+ public void setAuth(String auth) {
410
+
411
+ this.auth = auth;
412
+
413
+ }
414
+
415
+
416
+
417
+ public String getSectionID() {
418
+
419
+ return sectionID;
420
+
421
+ }
422
+
423
+ public void setSectionID(String sectionID) {
424
+
425
+ this.sectionID = sectionID;
426
+
427
+ }
428
+
429
+
430
+
431
+ public String getAddress() {
432
+
433
+ return address;
434
+
435
+ }
436
+
437
+ public void setAddress(String address) {
438
+
439
+ this.address = address;
440
+
441
+ }
442
+
443
+
444
+
445
+ public String getQual() {
446
+
447
+ return qual;
448
+
449
+ }
450
+
451
+ public void setQual(String qual) {
452
+
453
+ this.qual = qual;
454
+
455
+ }
456
+
457
+
458
+
459
+ public String getCreateUser() {
460
+
461
+ return createUser;
462
+
463
+ }
464
+
465
+ public void setCreateUser(String createUser) {
466
+
467
+ this.createUser = createUser;
468
+
469
+ }
470
+
471
+
472
+
473
+ public String getUpdateUser() {
474
+
475
+ return updateUser;
476
+
477
+ }
478
+
479
+ public void setUpdateUser(String updateUser) {
480
+
481
+ this.updateUser = updateUser;
482
+
483
+ }
484
+
485
+
486
+
487
+ public String getInvalidFlag() {
488
+
489
+ return invalidFlag;
490
+
491
+ }
492
+
493
+ public void setInvalidFlag(String invalidFlag) {
494
+
495
+ this.invalidFlag = invalidFlag;
496
+
497
+ }
498
+
499
+ }
500
+
501
+
502
+
503
+ ```
504
+
505
+ ```LoopListForm
506
+
507
+ package model;
508
+
509
+
510
+
511
+ import java.util.List;
512
+
513
+
514
+
515
+ import org.apache.struts.action.ActionForm;
516
+
517
+
518
+
519
+ public class LoopListForm extends ActionForm {
520
+
521
+ private List<UserActionForm> loop;
522
+
523
+
524
+
525
+ public void setLoop(List<UserActionForm> list) {
526
+
527
+ loop = list;
528
+
529
+ }
530
+
531
+ public List<UserActionForm> getLoop(){
532
+
533
+ return loop;
534
+
535
+ }
536
+
537
+ }
538
+
539
+
540
+
541
+ ```
542
+
543
+
544
+
545
+ 今の使い方としては、UserActionForm型のListのSetterに値を代入し、
546
+
547
+ そのListをLoopListFormに格納しています。
548
+
549
+ ```java
550
+
551
+ List<UserActionForm> list = new ArrayList<UserActionForm>();
552
+
553
+ LoopListForm loop = new LoopListForm();
554
+
555
+ ~省略~
556
+
557
+ UserActionForm uafList = new UserActionForm();
558
+
559
+  uafList.setUserID(userID);
560
+
561
+  uafList.setWorkTime(workingTime);
562
+
563
+  uafList.setOverTime(overTime);
564
+
565
+  uafList.setEarlyCount(earlyCount);
566
+
567
+  uafList.setLateCount(lateCount);
568
+
569
+  uafList.setWorks(count);
570
+
571
+
572
+
573
+  list.add(uafList);
574
+
575
+  loop.setLoop(list);
576
+
577
+  }
578
+
579
+
580
+
581
+ }
582
+
583
+
584
+
585
+
586
+
587
+ request.setAttribute("LoopListForm", loop);
588
+
589
+
590
+
591
+ ~省略~
592
+
593
+ ```
594
+
595
+
596
+
597
+ setAttributeした値はJSPで受け取っているのですが、
598
+
599
+ そこでキャストするときに詰まっています。
600
+
601
+
602
+
603
+ ```JSP
604
+
605
+ <%
606
+
607
+
608
+
609
+ List<model.LoopListForm> list = (List)request.getAttribute("LoopListForm"); //ここでキャストする方法がわからない。
610
+
611
+ if(list != null){
612
+
613
+ System.out.println(list);
614
+
615
+ System.out.println(list.size());
616
+
617
+ for(int i = 0 ; i < list.size() ; i++){
618
+
619
+
620
+
621
+ model.UserActionForm uaf = list.get(i);
622
+
623
+
624
+
625
+ %>
626
+
627
+
628
+
629
+ <label>名前:?</label><br>
630
+
631
+ <label>今月の勤務時間の合計:<%= uaf.getWorkTime() %>分</label><br>
632
+
633
+ <label>今月の残業時間の合計:<%= uaf.getOverTime() %>分</label><br>
634
+
635
+ <label>勤務日数:<%= uaf.getWorks() %>日</label><br>
636
+
637
+ <label>遅刻日数:<%= uaf.getLateCount() %>日</label><br>
638
+
639
+ <label>早退日数:<%= uaf.getEarlyCount() %>日</label><br>
640
+
641
+ ★★★★★
642
+
643
+
644
+
645
+ <br>
646
+
647
+ ```