質問編集履歴

3

Controllerクラスの変更箇所追記

2020/12/13 03:17

投稿

KeitaUenishi
KeitaUenishi

スコア0

test CHANGED
File without changes
test CHANGED
@@ -464,7 +464,7 @@
464
464
 
465
465
 
466
466
 
467
- CustomerListController.java
467
+ CustomerListController.java(変更箇所コメントアウト)
468
468
 
469
469
 
470
470
 

2

Controllerクラスの変更

2020/12/13 03:17

投稿

KeitaUenishi
KeitaUenishi

スコア0

test CHANGED
File without changes
test CHANGED
@@ -48,34 +48,16 @@
48
48
 
49
49
 
50
50
 
51
- Caused by: org.attoparser.ParseException: Error during execution of processor 'org.thymeleaf.spring5.processor.SpringInputGeneralFieldTagProcessor' (template: "/customer/customerNew" - line 20, col 58)
52
-
53
- at org.attoparser.MarkupParser.parseDocument(MarkupParser.java:393) ~[attoparser-2.0.5.RELEASE.jar:2.0.5.RELEASE]
54
-
55
- at org.attoparser.MarkupParser.parse(MarkupParser.java:257) ~[attoparser-2.0.5.RELEASE.jar:2.0.5.RELEASE]
56
-
57
- at org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parse(AbstractMarkupTemplateParser.java:230) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
58
-
59
- ... 98 common frames omitted
60
-
61
- Caused by: org.thymeleaf.exceptions.TemplateProcessingException: Error during execution of processor 'org.thymeleaf.spring5.processor.SpringInputGeneralFieldTagProcessor' (template: "/customer/customerNew" - line 20, col 58)
62
-
63
- at org.thymeleaf.processor.element.AbstractAttributeTagProcessor.doProcess(AbstractAttributeTagProcessor.java:117) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
51
+
52
+
53
+ 2020-12-12 12:50:45.889 ERROR 20136 --- [nio-8080-exec-7] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: "class path resource [templates//customer/customerNew.html]")] with root cause
54
+
55
+
56
+
57
+ java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'liveList' available as request attribute
64
58
 
65
59
 
66
60
 
67
- ... 113 common frames omitted
68
-
69
-
70
-
71
- 2020-12-12 12:50:45.889 ERROR 20136 --- [nio-8080-exec-7] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: "class path resource [templates//customer/customerNew.html]")] with root cause
72
-
73
-
74
-
75
- java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'liveList' available as request attribute
76
-
77
-
78
-
79
61
  ......
80
62
 
81
63
 
@@ -96,9 +78,397 @@
96
78
 
97
79
 
98
80
 
81
+ LiveList.java
82
+
83
+ ```java
84
+
85
+ package product.domain;
86
+
87
+
88
+
89
+ import java.util.List;
90
+
91
+
92
+
93
+ import javax.validation.constraints.Digits;
94
+
95
+ import javax.validation.constraints.NotBlank;
96
+
97
+ import javax.validation.constraints.NotNull;
98
+
99
+ import javax.validation.constraints.Size;
100
+
101
+
102
+
103
+ import lombok.Data;
104
+
105
+
106
+
107
+ @Data
108
+
109
+ public class LiveList {
110
+
111
+
112
+
113
+ /** 日付ID */
114
+
115
+ @NotNull
116
+
117
+ @Digits(integer = 8, fraction = 0)
118
+
119
+ private Long dateId;
120
+
121
+
122
+
123
+ /** 会場 */
124
+
125
+ @NotBlank
126
+
127
+ @Size(max = 32, message = "{error.maxsize}")
128
+
129
+ private String place;
130
+
131
+
132
+
133
+ /** 備考 */
134
+
135
+ private String remarks;
136
+
137
+
138
+
139
+ /** 子クラス(来場客リスト)の要素定義 */
140
+
141
+ private List<CustomerList> customers;
142
+
143
+
144
+
145
+ }
146
+
147
+
148
+
149
+
150
+
151
+ ```
152
+
153
+
154
+
155
+ CustomerList.java
156
+
157
+ ```java
158
+
159
+ package product.domain;
160
+
161
+
162
+
163
+ import javax.validation.constraints.Digits;
164
+
165
+ import javax.validation.constraints.NotBlank;
166
+
167
+ import javax.validation.constraints.NotNull;
168
+
169
+ import javax.validation.constraints.Size;
170
+
171
+
172
+
173
+ import lombok.Data;
174
+
175
+
176
+
177
+ @Data
178
+
179
+ public class CustomerList {
180
+
181
+
182
+
183
+ /** ID */
184
+
185
+ private Long id;
186
+
187
+
188
+
189
+ /** 日付ID */
190
+
191
+ @NotNull
192
+
193
+ @Digits(integer = 8, fraction = 0)
194
+
195
+ private Long dateId;
196
+
197
+
198
+
199
+ /** 名前 */
200
+
201
+ @NotBlank
202
+
203
+ @Size(min = 1, max = 50)
204
+
205
+ private String name;
206
+
207
+
208
+
209
+ /** 枚数 */
210
+
211
+ @NotNull
212
+
213
+ private int number;
214
+
215
+
216
+
217
+ /** 備考 */
218
+
219
+ private String comment;
220
+
221
+
222
+
223
+ }
224
+
225
+ ```
226
+
227
+
228
+
229
+ customerNew.html 
230
+
231
+ ```html 
232
+
233
+ <!DOCTYPE html>
234
+
235
+ <html xmlns:th="http://www.thymeleaf.org">
236
+
237
+ <head>
238
+
239
+ <meta charset="utf-8" />
240
+
241
+ <title>新規登録ページ</title>
242
+
243
+ <link rel="stylesheet" href="/css/bootstrap.css" />
244
+
245
+ <script src="/js/jquery.js"></script>
246
+
247
+ <script src="/js/bootstrap.js"></script>
248
+
249
+ </head>
250
+
251
+ <body>
252
+
253
+ <div class="container">
254
+
255
+ <h1>取り置きを新規登録</h1>
256
+
257
+
258
+
259
+ <form th:action="@{/customer}" th:method="post" th:object="${customerList}">
260
+
261
+ <p th:object="${liveList}">
262
+
263
+ <div class="form-group">
264
+
265
+ <input class="form-control"
266
+
267
+ type="hidden" name="id">
268
+
269
+ <input class="form-control"
270
+
271
+ type="hidden" name="dateId" th:object="${liveList}" th:field="${liveList.dateId}" />
272
+
273
+ </div>
274
+
275
+ <p/>
276
+
277
+ <div class="form-group">
278
+
279
+ <label class="control-label">名前</label> <input class="form-control"
280
+
281
+ type="text" name="name" />
282
+
283
+ <span class="text-danger" th:if="${#fields.hasErrors('name')}" th:errors="*{customerList.name}"></span>
284
+
285
+ </div>
286
+
287
+ <div class="form-group">
288
+
289
+ <label class="control-label">枚数</label> <input class="form-control"
290
+
291
+ type="number" name="number" />
292
+
293
+ <span class="text-danger" th:if="${#fields.hasErrors('number')}" th:errors="*{customerList.number}"></span>
294
+
295
+ </div>
296
+
297
+ <div class="form-group">
298
+
299
+ <label class="control-label">メモ</label> <input class="form-control"
300
+
301
+ type="text" name="comment" />
302
+
303
+ </div>
304
+
305
+ <button class="btn btn-Primary" type="submit">登録</button>
306
+
307
+ </form>
308
+
309
+ <div class="pull-right">
310
+
311
+ <a class="btn btn-link" href="/liveList">一覧画面へ</a>
312
+
313
+ </div>
314
+
315
+ </div>
316
+
317
+ </body>
318
+
319
+ </html>
320
+
321
+ ```
322
+
323
+
324
+
325
+
326
+
327
+ ### 試したこと
328
+
329
+
330
+
331
+ Controllerから受け渡す値の確認
332
+
333
+ BindingResultの位置確認(@validのあとにする)
334
+
335
+ view側でのth:objectで受け取る値の変更、追加
336
+
337
+ エラー文にある「Neither BindingResult nor plain target object for bean name 'liveList' available as request attribute」にあるように、画面から送る値か受け取っている値に何らかの問題があるとみているのですがどう問題があるかがわからない状態です。
338
+
339
+
340
+
341
+ 初学者のため初歩の質問かもしれませんが、何卒ご教授いただけると幸いです。
342
+
343
+
344
+
345
+ 新規登録で各項目を空白にした場合のデバッグ画面
346
+
347
+ ![![イメージ説明](c3a0b80976fbc8e29d110ff68151c1e5.png)](2ba4114e31d04207e365f96533f77a1e.png)
348
+
349
+
350
+
351
+ ### 補足情報(FW/ツールのバージョンなど)
352
+
353
+
354
+
355
+ OS Windows10
356
+
357
+ IDE Eclipse Version: 2020-06 (4.16.0)
358
+
359
+ java 11
360
+
361
+ Spring Boot 2.4.0
362
+
363
+
364
+
365
+ [GitHub](https://github.com/KeitaUenishi/TicketManegerTool.git)
366
+
367
+
368
+
369
+ ###追記
370
+
371
+
372
+
373
+ customerNew.html(変更後)
374
+
375
+ ```
376
+
377
+ <!DOCTYPE html>
378
+
379
+ <html xmlns:th="http://www.thymeleaf.org">
380
+
381
+ <head>
382
+
383
+ <meta charset="utf-8" />
384
+
385
+ <title>新規登録ページ</title>
386
+
387
+ <link rel="stylesheet" href="/css/bootstrap.css" />
388
+
389
+ <script src="/js/jquery.js"></script>
390
+
391
+ <script src="/js/bootstrap.js"></script>
392
+
393
+ </head>
394
+
395
+ <body>
396
+
397
+ <div class="container">
398
+
399
+ <h1>取り置きを新規登録</h1>
400
+
401
+
402
+
403
+ <form th:action="@{/customer}" th:method="post" th:object="${customerList}">
404
+
405
+ <div class="form-group">
406
+
407
+ <input class="form-control"
408
+
409
+ type="hidden" name="id">
410
+
411
+ <input class="form-control"
412
+
413
+ type="hidden" name="dateId" th:field="${customerList.dateId}" />
414
+
415
+ </div>
416
+
417
+
418
+
419
+ <div class="form-group">
420
+
421
+ <label class="control-label">名前</label> <input class="form-control"
422
+
423
+ type="text" name="name" />
424
+
425
+ <span class="text-danger" th:if="${#fields.hasErrors('name')}" th:errors="*{customerList.name}"></span>
426
+
427
+ </div>
428
+
429
+ <div class="form-group">
430
+
431
+ <label class="control-label">枚数</label> <input class="form-control"
432
+
433
+ type="number" name="number" />
434
+
435
+ <span class="text-danger" th:if="${#fields.hasErrors('number')}" th:errors="*{customerList.number}"></span>
436
+
437
+ </div>
438
+
439
+ <div class="form-group">
440
+
441
+ <label class="control-label">メモ</label> <input class="form-control"
442
+
443
+ type="text" name="comment" />
444
+
445
+ </div>
446
+
447
+ <button class="btn btn-Primary" type="submit" >登録</button> <!-- th:href="@{/customer/customerNew/{dateId}(dateId=*{dateId})}" -->
448
+
449
+ </form>
450
+
451
+ <div class="pull-right">
452
+
453
+ <a class="btn btn-link" href="/liveList">一覧画面へ</a>
454
+
455
+ </div>
456
+
457
+ </div>
458
+
459
+ </body>
460
+
461
+ </html>
462
+
463
+ ```
464
+
465
+
466
+
99
- CustomerListController.Java
467
+ CustomerListController.java
100
-
468
+
469
+
470
+
101
- ```Java
471
+ ```
102
472
 
103
473
  package product.controller;
104
474
 
@@ -132,8 +502,6 @@
132
502
 
133
503
  import product.domain.CustomerList;
134
504
 
135
- import product.domain.LiveList;
136
-
137
505
  import product.service.CustomerListService;
138
506
 
139
507
  import product.service.LiveListService;
@@ -178,9 +546,9 @@
178
546
 
179
547
  Model model) {
180
548
 
181
- LiveList liveList = liveListService.findOne(dateId);
549
+ //LiveList liveList = liveListService.findOne(dateId);
182
-
550
+
183
- model.addAttribute("liveList", liveList);
551
+ //model.addAttribute("liveList", liveList);
184
552
 
185
553
  model.addAttribute("customerList", customerList);
186
554
 
@@ -208,8 +576,6 @@
208
576
 
209
577
  // customerデータの保存
210
578
 
211
- // @Valid @ModelAttribute LiveList liveList,b
212
-
213
579
  @PostMapping
214
580
 
215
581
  public String customerCreate(
@@ -276,292 +642,4 @@
276
642
 
277
643
  }
278
644
 
279
-
280
-
281
- ```
645
+ ```
282
-
283
- LiveList.java
284
-
285
- ```java
286
-
287
- package product.domain;
288
-
289
-
290
-
291
- import java.util.List;
292
-
293
-
294
-
295
- import javax.validation.constraints.Digits;
296
-
297
- import javax.validation.constraints.NotBlank;
298
-
299
- import javax.validation.constraints.NotNull;
300
-
301
- import javax.validation.constraints.Size;
302
-
303
-
304
-
305
- import lombok.Data;
306
-
307
-
308
-
309
- @Data
310
-
311
- public class LiveList {
312
-
313
-
314
-
315
- /** 日付ID */
316
-
317
- @NotNull
318
-
319
- @Digits(integer = 8, fraction = 0)
320
-
321
- private Long dateId;
322
-
323
-
324
-
325
- /** 会場 */
326
-
327
- @NotBlank
328
-
329
- @Size(max = 32, message = "{error.maxsize}")
330
-
331
- private String place;
332
-
333
-
334
-
335
- /** 備考 */
336
-
337
- private String remarks;
338
-
339
-
340
-
341
- /** 子クラス(来場客リスト)の要素定義 */
342
-
343
- private List<CustomerList> customers;
344
-
345
-
346
-
347
- }
348
-
349
-
350
-
351
-
352
-
353
- ```
354
-
355
-
356
-
357
- CustomerList.java
358
-
359
- ```java
360
-
361
- package product.domain;
362
-
363
-
364
-
365
- import javax.validation.constraints.Digits;
366
-
367
- import javax.validation.constraints.NotBlank;
368
-
369
- import javax.validation.constraints.NotNull;
370
-
371
- import javax.validation.constraints.Size;
372
-
373
-
374
-
375
- import lombok.Data;
376
-
377
-
378
-
379
- @Data
380
-
381
- public class CustomerList {
382
-
383
-
384
-
385
- /** ID */
386
-
387
- private Long id;
388
-
389
-
390
-
391
- /** 日付ID */
392
-
393
- @NotNull
394
-
395
- @Digits(integer = 8, fraction = 0)
396
-
397
- private Long dateId;
398
-
399
-
400
-
401
- /** 名前 */
402
-
403
- @NotBlank
404
-
405
- @Size(min = 1, max = 50)
406
-
407
- private String name;
408
-
409
-
410
-
411
- /** 枚数 */
412
-
413
- @NotNull
414
-
415
- private int number;
416
-
417
-
418
-
419
- /** 備考 */
420
-
421
- private String comment;
422
-
423
-
424
-
425
- }
426
-
427
- ```
428
-
429
-
430
-
431
- customerNew.html 
432
-
433
- ```html 
434
-
435
- <!DOCTYPE html>
436
-
437
- <html xmlns:th="http://www.thymeleaf.org">
438
-
439
- <head>
440
-
441
- <meta charset="utf-8" />
442
-
443
- <title>新規登録ページ</title>
444
-
445
- <link rel="stylesheet" href="/css/bootstrap.css" />
446
-
447
- <script src="/js/jquery.js"></script>
448
-
449
- <script src="/js/bootstrap.js"></script>
450
-
451
- </head>
452
-
453
- <body>
454
-
455
- <div class="container">
456
-
457
- <h1>取り置きを新規登録</h1>
458
-
459
-
460
-
461
- <form th:action="@{/customer}" th:method="post" th:object="${customerList}">
462
-
463
- <p th:object="${liveList}">
464
-
465
- <div class="form-group">
466
-
467
- <input class="form-control"
468
-
469
- type="hidden" name="id">
470
-
471
- <input class="form-control"
472
-
473
- type="hidden" name="dateId" th:object="${liveList}" th:field="${liveList.dateId}" />
474
-
475
- </div>
476
-
477
- <p/>
478
-
479
- <div class="form-group">
480
-
481
- <label class="control-label">名前</label> <input class="form-control"
482
-
483
- type="text" name="name" />
484
-
485
- <span class="text-danger" th:if="${#fields.hasErrors('name')}" th:errors="*{customerList.name}"></span>
486
-
487
- </div>
488
-
489
- <div class="form-group">
490
-
491
- <label class="control-label">枚数</label> <input class="form-control"
492
-
493
- type="number" name="number" />
494
-
495
- <span class="text-danger" th:if="${#fields.hasErrors('number')}" th:errors="*{customerList.number}"></span>
496
-
497
- </div>
498
-
499
- <div class="form-group">
500
-
501
- <label class="control-label">メモ</label> <input class="form-control"
502
-
503
- type="text" name="comment" />
504
-
505
- </div>
506
-
507
- <button class="btn btn-Primary" type="submit">登録</button>
508
-
509
- </form>
510
-
511
- <div class="pull-right">
512
-
513
- <a class="btn btn-link" href="/liveList">一覧画面へ</a>
514
-
515
- </div>
516
-
517
- </div>
518
-
519
- </body>
520
-
521
- </html>
522
-
523
- ```
524
-
525
-
526
-
527
-
528
-
529
- ### 試したこと
530
-
531
-
532
-
533
- Controllerから受け渡す値の確認
534
-
535
- BindingResultの位置確認(@validのあとにする)
536
-
537
- view側でのth:objectで受け取る値の変更、追加
538
-
539
- エラー文にある「Neither BindingResult nor plain target object for bean name 'liveList' available as request attribute」にあるように、画面から送る値か受け取っている値に何らかの問題があるとみているのですがどう問題があるかがわからない状態です。
540
-
541
-
542
-
543
- 初学者のため初歩の質問かもしれませんが、何卒ご教授いただけると幸いです。
544
-
545
-
546
-
547
- 新規登録で各項目を空白にした場合のデバッグ画面
548
-
549
- ![![イメージ説明](c3a0b80976fbc8e29d110ff68151c1e5.png)](2ba4114e31d04207e365f96533f77a1e.png)
550
-
551
-
552
-
553
- ### 補足情報(FW/ツールのバージョンなど)
554
-
555
-
556
-
557
- OS Windows10
558
-
559
- IDE Eclipse Version: 2020-06 (4.16.0)
560
-
561
- java 11
562
-
563
- Spring Boot 2.4.0
564
-
565
-
566
-
567
- [GitHub](https://github.com/KeitaUenishi/TicketManegerTool.git)

1

CustomerList,LiveListクラスの追記

2020/12/13 03:16

投稿

KeitaUenishi
KeitaUenishi

スコア0

test CHANGED
File without changes
test CHANGED
@@ -96,6 +96,8 @@
96
96
 
97
97
 
98
98
 
99
+ CustomerListController.Java
100
+
99
101
  ```Java
100
102
 
101
103
  package product.controller;
@@ -278,9 +280,157 @@
278
280
 
279
281
  ```
280
282
 
281
-
283
+ LiveList.java
284
+
282
-
285
+ ```java
286
+
287
+ package product.domain;
288
+
289
+
290
+
291
+ import java.util.List;
292
+
293
+
294
+
295
+ import javax.validation.constraints.Digits;
296
+
297
+ import javax.validation.constraints.NotBlank;
298
+
299
+ import javax.validation.constraints.NotNull;
300
+
301
+ import javax.validation.constraints.Size;
302
+
303
+
304
+
305
+ import lombok.Data;
306
+
307
+
308
+
309
+ @Data
310
+
311
+ public class LiveList {
312
+
313
+
314
+
315
+ /** 日付ID */
316
+
317
+ @NotNull
318
+
319
+ @Digits(integer = 8, fraction = 0)
320
+
321
+ private Long dateId;
322
+
323
+
324
+
325
+ /** 会場 */
326
+
327
+ @NotBlank
328
+
329
+ @Size(max = 32, message = "{error.maxsize}")
330
+
331
+ private String place;
332
+
333
+
334
+
335
+ /** 備考 */
336
+
337
+ private String remarks;
338
+
339
+
340
+
341
+ /** 子クラス(来場客リスト)の要素定義 */
342
+
343
+ private List<CustomerList> customers;
344
+
345
+
346
+
347
+ }
348
+
349
+
350
+
351
+
352
+
353
+ ```
354
+
355
+
356
+
357
+ CustomerList.java
358
+
359
+ ```java
360
+
361
+ package product.domain;
362
+
363
+
364
+
365
+ import javax.validation.constraints.Digits;
366
+
367
+ import javax.validation.constraints.NotBlank;
368
+
369
+ import javax.validation.constraints.NotNull;
370
+
371
+ import javax.validation.constraints.Size;
372
+
373
+
374
+
375
+ import lombok.Data;
376
+
377
+
378
+
379
+ @Data
380
+
381
+ public class CustomerList {
382
+
383
+
384
+
385
+ /** ID */
386
+
387
+ private Long id;
388
+
389
+
390
+
391
+ /** 日付ID */
392
+
393
+ @NotNull
394
+
395
+ @Digits(integer = 8, fraction = 0)
396
+
397
+ private Long dateId;
398
+
399
+
400
+
401
+ /** 名前 */
402
+
403
+ @NotBlank
404
+
405
+ @Size(min = 1, max = 50)
406
+
407
+ private String name;
408
+
409
+
410
+
411
+ /** 枚数 */
412
+
413
+ @NotNull
414
+
415
+ private int number;
416
+
417
+
418
+
419
+ /** 備考 */
420
+
421
+ private String comment;
422
+
423
+
424
+
425
+ }
426
+
427
+ ```
428
+
429
+
430
+
431
+ customerNew.html 
432
+
283
- ```html
433
+ ```html 
284
434
 
285
435
  <!DOCTYPE html>
286
436