質問編集履歴
6
タイトル改善
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
|
1
|
+
form:errorsをネストして使用したい
|
body
CHANGED
File without changes
|
5
書式の改善
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,17 +1,32 @@
|
|
1
1
|
お世話になります。
|
2
2
|
|
3
|
-
bootstrapと
|
3
|
+
bootstrapとspringbootを使用しています
|
4
|
-
|
4
|
+
バリデーションエラーの際に<form:errors>を使用しており、その表示の仕方を工夫したいと考えています。
|
5
|
+
そこで、bootstrapの[アラート](https://getbootstrap.jp/docs/4.3/components/alerts/)表示のようにしたいです。
|
5
6
|
|
7
|
+
しかし、errorsタグが有効になっている事を判断できる変数が作れません...
|
8
|
+
初めはerrorsタグでアラート部分を囲ってみましたが、それだとerrorsタグをネスト出来ない為に、プロパティファイルで用意されているメッセージを表示できません。
|
9
|
+
|
10
|
+
エラーになっているか判断するための変数か、「エラーが出た際」にプロパティで用意されているメッセージを用意してくれる実装はありますか?
|
11
|
+
その他での解決策でも歓迎です。
|
12
|
+
|
13
|
+
以下、エラーが発生した際イメージを書きます。
|
14
|
+
|
6
15
|
```jsp
|
16
|
+
<%@ page language="java" contentType="text/html; charset=UTF-8" %>
|
17
|
+
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
|
18
|
+
<html>
|
19
|
+
<head>
|
20
|
+
<!-- js,cssの読み込み -->
|
21
|
+
</head>
|
22
|
+
<body>
|
23
|
+
<!-- ここを「エラーメッセージが出た際」で条件分岐したい -->
|
7
|
-
<div class="alert alert-danger alert-dismissible show" role="alert">
|
24
|
+
<div class="alert alert-danger alert-dismissible show" role="alert">
|
8
|
-
|
25
|
+
<strong><form:errors path="hoge"/></strong>
|
9
|
-
|
26
|
+
<button type="button" class="close" data-dismiss="alert">
|
10
|
-
|
27
|
+
<span aria-hidden="true">×</span>
|
11
|
-
|
28
|
+
</button>
|
12
|
-
</div>
|
29
|
+
</div>
|
30
|
+
</body>
|
31
|
+
</html>
|
13
|
-
```
|
32
|
+
```
|
14
|
-
|
15
|
-
しかし、これではエラーが起きなかった場合でもアラートの枠組みが表示されてしまいます。
|
16
|
-
エラーが出なかったときは何も表示したくありません。
|
17
|
-
これを解決する方法はありますか?
|
4
タグ更新
title
CHANGED
File without changes
|
body
CHANGED
File without changes
|
3
回答を得られやすくするタイトルに変更
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
|
1
|
+
Springのform:errorsを動的に使用したい
|
body
CHANGED
File without changes
|
2
タグの追加
title
CHANGED
File without changes
|
body
CHANGED
File without changes
|
1
タグの追加
title
CHANGED
File without changes
|
body
CHANGED
File without changes
|