teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

6

タイトル改善

2019/11/28 05:13

投稿

makosankibu
makosankibu

スコア289

title CHANGED
@@ -1,1 +1,1 @@
1
- Springのform:errorsを動的に使用したい
1
+ form:errorsをネストして使用したい
body CHANGED
File without changes

5

書式の改善

2019/11/28 05:13

投稿

makosankibu
makosankibu

スコア289

title CHANGED
File without changes
body CHANGED
@@ -1,17 +1,32 @@
1
1
  お世話になります。
2
2
 
3
- bootstrapとspringを使用しています
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
- <strong><form:errors path="hoge"/></strong>
25
+ <strong><form:errors path="hoge"/></strong>
9
- <button type="button" class="close" data-dismiss="alert" aria-label="Close">
26
+ <button type="button" class="close" data-dismiss="alert">
10
- <span aria-hidden="true">&times;</span>
27
+ <span aria-hidden="true">&times;</span>
11
- </button>
28
+ </button>
12
- </div>
29
+ </div>
30
+ </body>
31
+ </html>
13
- ```
32
+ ```
14
-
15
- しかし、これではエラーが起きなかった場合でもアラートの枠組みが表示されてしまいます。
16
- エラーが出なかったときは何も表示したくありません。
17
- これを解決する方法はありますか?

4

タグ更新

2019/11/27 02:06

投稿

makosankibu
makosankibu

スコア289

title CHANGED
File without changes
body CHANGED
File without changes

3

回答を得られやすくするタイトルに変更

2019/11/22 00:19

投稿

makosankibu
makosankibu

スコア289

title CHANGED
@@ -1,1 +1,1 @@
1
- SpringBootのform:errorsをBootstrap4のアラートで使用したい
1
+ Springのform:errorsを動的に使用したい
body CHANGED
File without changes

2

タグの追加

2019/11/21 06:25

投稿

makosankibu
makosankibu

スコア289

title CHANGED
File without changes
body CHANGED
File without changes

1

タグの追加

2019/11/21 00:27

投稿

makosankibu
makosankibu

スコア289

title CHANGED
File without changes
body CHANGED
File without changes