バリデーションエラー時のメッセージが一つしか出力されない

実現したいこと

前提

Springでユーザーがformに入力した値をバリデーションチェックし、エラーであればエラーメッセージを表示する処理を作っています

発生している問題・エラーメッセージ

二項目のうち、一項目(日本語名:日付)はバリデーションエラー時にメッセージ出力されますが、もう一項目(日本語名:題名)は何も出力されません。

該当のソースコード

HTML

1 <form method="post" th:action="@{/input}" th:object="${columnForm}"> 2 <input type="hidden" id="userId" name="userId" th:field="*{userId}" /> 3 4 <label for="editDate">日付</label> 5 <input type="date" id="editDate" name="editDate" th:field="*{editDate}" /><br /> 6 <p th:if="${#fields.hasErrors('editDate')}" th:errors="*{editDate}">日付を選んでください</p> 7 8 <label for="title">題名</label> 9 <input type="text" id="title" name="title" th:field="*{title}" /><br /> 10 <p th:if="${#fields.hasErrors('title')}" th:errors="*{title}">入力必須です</p> 11

Java

1package com.example.demo;2 3import java.time.LocalDate;4 5import org.springframework.format.annotation.DateTimeFormat;6 7import jakarta.validation.constraints.NotNull;8import lombok.Data;9 10@Data11public class ColumnForm {12 @NotNull13 private Integer userId;14 @NotNull(message = "日付を選んでください")15 @DateTimeFormat(pattern = "yyyy/MM/dd")16 private LocalDate editDate;17 @NotNull(message = "題名を入力してください")18 private String title;19 private String event;20 private String emotion;21 private String negative;22 private String distortion;23 private String reason;24 private String disproof;25 private String another;26 private String changeEmo;27}

試したこと

@NotNullアノテーションにmessageを指定してみましたが、それでもダメでした。

補足情報(FW/ツールのバージョンなど)

spring-boot3.1.2-SNAPSHOT
JDK17

よろしくお願いいたします。

コメントを投稿

0 コメント