質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

HTML

HTMLとは、ウェブ上の文書を記述・作成するためのマークアップ言語のことです。文章の中に記述することで、文書の論理構造などを設定することができます。ハイパーリンクを設定できるハイパーテキストであり、画像・リスト・表などのデータファイルをリンクする情報に結びつけて情報を整理します。現在あるネットワーク上のほとんどのウェブページはHTMLで作成されています。

Spring Boot

Spring Bootは、Javaのフレームワークの一つ。Springプロジェクトが提供する様々なフレームワークを統合した、アプリケーションを高速で開発するために設計されたフレームワークです。

Q&A

解決済

1回答

878閲覧

他ファイルから値をとり、ドロップダウンリスト作成

tsukasada

総合スコア45

Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

HTML

HTMLとは、ウェブ上の文書を記述・作成するためのマークアップ言語のことです。文章の中に記述することで、文書の論理構造などを設定することができます。ハイパーリンクを設定できるハイパーテキストであり、画像・リスト・表などのデータファイルをリンクする情報に結びつけて情報を整理します。現在あるネットワーク上のほとんどのウェブページはHTMLで作成されています。

Spring Boot

Spring Bootは、Javaのフレームワークの一つ。Springプロジェクトが提供する様々なフレームワークを統合した、アプリケーションを高速で開発するために設計されたフレームワークです。

0グッド

0クリップ

投稿2022/04/18 07:58

Spring Tool Suite バージョン4 で
Bootstrap バージョン3.3.2
PostgreSQL<バージョン>9.6
で、LmsUserRoleEnum.javaの初期値は「受講生」とし、resetPassword.htmlにプルダウンを作成したいですが、以下のように記述しても反映されません。
どのように記載すれば反映されるでしょうか?
また、権限IDと権限名が対になったMAPを「LmsUserRoleEnum.java」を使用して作成し、Controller側でパスワード再設定画面に表示させるための処理を追加したいです。

resetPassword.html

1<div class="pull-down" style=text-align:right;> 2 <label>権限</label> 3 <select th:name="e" th:value="${STUDENT}" style=width:150px;> 4 <option th:value="${STUDENT}"></option> 5 <option th:value="${TEACHER}"></option> 6 <option th:value="${COMPANY_SUBSIDY}"></option> 7 <option th:value="${ADMIN}"></option> 8 <option th:value="${COMPANY_TRAINING}"></option> 9 </select> 10 </div> 11

LmsUserRoleEnum.java

1package jp.co.sss.lms.enums; 2 3import jp.co.sss.lms.util.Constants; 4 5/** 6 * 権限名称変換 7 * 8 * @author 東京ITスクール 9 */ 10public enum LmsUserRoleEnum { 11 STUDENT(Constants.CODE_VAL_ROLL_STUDENT, "受講生"), TEACHER(Constants.CODE_VAL_ROLL_TEACHER, "講師"), 12 COMPANY_SUBSIDY(Constants.CODE_VAL_ROLL_COMPANY, "企業担当者"), ADMIN((Constants.CODE_VAL_ROLL_ADMIN), "管理者"), 13 COMPANY_TRAINING(Constants.CODE_VAL_ROLL_TRAINING, "育成担当者"),; 14 15 public String code; 16 public String value; 17 18 private LmsUserRoleEnum(String code, String value) { 19 this.code = code; 20 this.value = value; 21 } 22 23 public static LmsUserRoleEnum getEnum(String code) { 24 for (LmsUserRoleEnum e : LmsUserRoleEnum.values()) { 25 if (e.code.equals(code)) { 26 return e; 27 } 28 } 29 return null; 30 } 31 32}

PasswordController.java

1package jp.co.sss.lms.controller; 2 3import java.util.Date; 4 5import javax.servlet.http.HttpServletRequest; 6 7import org.apache.commons.lang3.StringUtils; 8import org.slf4j.Logger; 9import org.slf4j.LoggerFactory; 10import org.springframework.beans.factory.annotation.Autowired; 11import org.springframework.stereotype.Controller; 12import org.springframework.ui.Model; 13import org.springframework.validation.BindingResult; 14import org.springframework.validation.annotation.Validated; 15import org.springframework.web.bind.annotation.ModelAttribute; 16import org.springframework.web.bind.annotation.RequestMapping; 17import org.springframework.web.bind.annotation.RequestMethod; 18import org.springframework.web.bind.annotation.RequestParam; 19import org.springframework.web.servlet.mvc.support.RedirectAttributes; 20 21import jp.co.sss.lms.entity.TTemporaryPassStorage; 22import jp.co.sss.lms.enums.LmsUserRoleEnum; 23import jp.co.sss.lms.exception.NoLoginException; 24import jp.co.sss.lms.form.ChangePasswordGroup; 25import jp.co.sss.lms.form.LoginForm; 26import jp.co.sss.lms.form.MailAddressForm; 27import jp.co.sss.lms.form.ResetPasswordGroup; 28import jp.co.sss.lms.mapper.TTemporaryPassStorageMapper; 29import jp.co.sss.lms.service.LoginService; 30import jp.co.sss.lms.service.PasswordService; 31import jp.co.sss.lms.util.Constants; 32import jp.co.sss.lms.util.LoggingUtil; 33import jp.co.sss.lms.util.LoginUserUtil; 34import jp.co.sss.lms.util.MessageUtil; 35 36/** 37 * パスワードコントローラー 38 * 39 * @author 東京ITスクール 40 */ 41@Controller 42@RequestMapping("/password") 43public class PasswordController { 44 45 @Autowired 46 private PasswordService passwordService; 47 @Autowired 48 private LoginService loginService; 49 @Autowired 50 private MessageUtil messageUtil; 51 @Autowired 52 private LoggingUtil loggingUtil; 53 @Autowired 54 private TTemporaryPassStorageMapper tTemporaryPassStorageMapper; 55 @Autowired 56 private LoginUserUtil loginUserUtil; 57 58 private final Logger logger = LoggerFactory.getLogger(getClass()); 59 60 /** 61 * パスワード変更画面に遷移 62 * 63 * @return パスワード変更画面 64 */ 65 @RequestMapping(value = "/changePassword") 66 public String index(@ModelAttribute LoginForm loginForm) { 67 return "password/changePassword"; 68 } 69 70 /** 71 * 変更ボタン押下 72 * 73 * @return 遷移先画面 74 */ 75 @RequestMapping(value = "/changePassword/change", method = RequestMethod.POST) 76 public String change(@Validated(ChangePasswordGroup.class) @ModelAttribute LoginForm loginForm, 77 BindingResult result, Model model) { 78 // 変更後のパスワードと確認パスワードが一致してるかチェック。不一致ならエラーにする。 79 if (result.hasErrors()) { 80 return "/password/changePassword"; 81 } 82 83 // 相関チェック 84 result = passwordService.changePassword(loginForm, result); 85 if (result.hasErrors()) { 86 if (result.hasFieldErrors("userDetail")) { 87 return "redirect:/logout"; 88 } 89 if (result.hasFieldErrors("updateFaild")) { 90 model.addAttribute("updateFaild", result.getFieldError("updateFaild").getDefaultMessage()); 91 } 92 return "/password/changePassword"; 93 } 94 95 return sendDisp(); 96 } 97 98 /** 99 * ログイン画面からパスワード再設定画面 100 * 101 * @return resetPasswordへの遷移 102 */ 103 @RequestMapping(value = "/resetPassword", method = RequestMethod.GET) 104 public String index(@ModelAttribute MailAddressForm form, Model model) { 105 106 // 設定ファイルのメール送信フラグが0の場合、メッセージ表示処理を追加 107 boolean sendFlg = messageUtil.getMessage("setting.mail.send.flg").equals("0") ? true : false; 108 model.addAttribute("sendFlg", sendFlg); 109 110 return "/password/resetPassword"; 111 } 112 113 /** 114 * resetPasswordからcompleteへの遷移<br> 115 * ※送信ボタン押下時<br> 116 * 117 * @return completeへの遷移 118 */ 119 @RequestMapping(value = "/resetPassword/complete", method = RequestMethod.POST) 120 public String complete(@ModelAttribute MailAddressForm mailAddressForm, BindingResult result, HttpServletRequest request, Model model) { 121 122 // 入力値のバリデーションチェック 123 if (result.hasErrors()) { 124 return "/password/resetPassword"; 125 } 126 // @author Takada Seizo – TASK.05 127 passwordService.registTemporaryPassStorage(mailAddressForm.getMailAddress(), mailAddressForm.getKengen()); 128 129 String sendFlg = messageUtil.getMessage("setting.mail.send.flg"); 130 if (!sendFlg.equals("0")) { 131 passwordService.sendPasswordResetMail(request, mailAddressForm.getMailAddress()); 132 } 133 134 model.addAttribute("mailAddress", mailAddressForm.getMailAddress()); 135 model.addAttribute("timeLimit", messageUtil.getMessage("setting.timelimit.hour")); 136 137 return "/password/complete"; 138 } 139 140 /** 141 * メールからのパスワード変更 142 * 143 * @param redirectAttributes 144 * @param key 145 * @param model 146 * @return パスワード変更画面 147 */ 148 @RequestMapping(value = "/resetPassword/set", method = RequestMethod.GET) 149 public String set(RedirectAttributes redirectAttributes, @RequestParam("key") String key, Model model) { 150 151 // keyに該当するデータが無いまたは、制限時間を過ぎている場合にエラー画面に遷移 152 TTemporaryPassStorage tTemporaryPassStorage = tTemporaryPassStorageMapper.findByChangeKey(key, Constants.DB_FLG_FALSE); 153 if (tTemporaryPassStorage == null || tTemporaryPassStorage.getTimeLimit().compareTo(new Date()) < 0) { 154 StringBuffer sb = new StringBuffer(messageUtil.getMessage(Constants.VALID_KEY_TOKEN)); 155 loggingUtil.appendLog(sb); 156 logger.info(sb.toString()); 157 158 model.addAttribute("timeLimit", messageUtil.getMessage("setting.timelimit.hour")); 159 model.addAttribute("tismail", messageUtil.getMessage("setting.tismail")); 160 return "/password/error"; 161 } 162 163 redirectAttributes.addFlashAttribute("tTemporaryPassStorage", tTemporaryPassStorage); 164 165 // パスワード変更画面へ遷移 166 return "redirect:/password/changePassword/mailInput"; 167 } 168 169 /** 170 * パスワード再設定からのパスワード変更画面の初期表示 171 * @param tTemporaryPassStorage 172 * @param loginForm 173 * 174 * @return 遷移先画面 175 */ 176 @RequestMapping(value = "/changePassword/mailInput") 177 public String mailinput(@ModelAttribute("tTemporaryPassStorage") TTemporaryPassStorage tTemporaryPassStorage, 178 @ModelAttribute LoginForm loginForm) { 179 180 // ログインID取得 181 String loginId = loginService.getLoginId(tTemporaryPassStorage.getUserId()); 182 183 if (StringUtils.isBlank(loginId)) { 184 return "/password/error"; 185 } else { 186 loginForm.setLoginId(loginId); 187 return "/password/mailInput"; 188 } 189 } 190 191 /** 192 * パスワード再設定完了 193 * 194 * @param loginForm 195 * @param result 196 * @param model 197 * @return パスワード再設定完了後画面 198 */ 199 @RequestMapping(value = "/changePassword/mailComplete", method = RequestMethod.POST) 200 public String mailComplete(@Validated(ResetPasswordGroup.class) @ModelAttribute LoginForm loginForm, 201 BindingResult result, Model model) { 202 203 // バリデーションチェック 204 if (result.hasErrors()) { 205 return "/password/mailInput"; 206 } 207 208 // 相関チェック 209 result = passwordService.changePasswordMailInput(loginForm, result); 210 if (result.hasErrors()) { 211 if (result.hasFieldErrors("updateFaild")) { 212 model.addAttribute("updateFaild", result.getFieldError("updateFaild").getDefaultMessage()); 213 } 214 return "/password/mailInput"; 215 } 216 217 return sendDisp(); 218 } 219 220 // 権限ごとの画面遷移先 221 private String sendDisp() { 222 if (loginUserUtil.isStudent()) { 223 return "redirect:/course/detail"; 224 } else if (loginUserUtil.isCompany()) { 225 return "redirect:/user/list"; 226 } else if (loginUserUtil.isTraining()) { 227 return "redirect:/user/list"; 228 } else if (loginUserUtil.isTeacher()) { 229 //@author SeungHyun Lim – TASK38 230 return "redirect:/course/list"; 231 } else if (loginUserUtil.isAdmin()) { 232 return "redirect:/course/list"; 233 } else { 234 throw new NoLoginException(); 235 } 236 } 237 238} 239

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

resetPassword.htmlにプルダウンを作成したい

LmsUserRoleEnum.values() で Enum 一覧を配列化できますので、活用なさっていただくのが良いと思います。

権限IDと権限名が対になったMAPを「LmsUserRoleEnum.java」を使用して作成し、Controller側でパスワード再設定画面に表示させるための処理を追加したいです。

権限の何をどのように表示するのかが分からないので、お答えできません。


※ LmsUserRoleEnum はそのまま使用します

resetPassword.html

1<!doctype html> 2<html xmlns:th="http://www.thymeleaf.org"> 3<head> 4 <title>Thymeleaf</title> 5 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 6</head> 7<body> 8 9 <form action="resetPassword"> 10 11 <div class="pull-down" style="text-align: left;"> 12 <label>権限</label> 13 <select th:name="code" style="width: 150px;"> 14 <option th:each="role : ${roles}" th:value="${role.code}" th:inline="text">[[${role.value}]]</option> 15 </select> 16 </div> 17 18 <input type="submit"> 19 </form> 20 <p th:if="${selected != null}">前回は「[[${selected.value}]]」が選択されています。</p> 21 22</body> 23</html>

PasswordController.java

1 2package jp.co.sss.lms.controller; 3 4import org.springframework.stereotype.Controller; 5import org.springframework.ui.Model; 6import org.springframework.web.bind.annotation.ModelAttribute; 7import org.springframework.web.bind.annotation.RequestMapping; 8import org.springframework.web.bind.annotation.RequestMethod; 9 10import jp.co.sss.lms.enums.LmsUserRoleEnum; 11import jp.co.sss.lms.form.MailAddressForm; 12 13/** 14 * パスワードコントローラー 15 * 16 * @author 17 */ 18@Controller 19@RequestMapping("/password") 20public class PasswordController { 21 22 /** 23 * ログイン画面からパスワード再設定画面 24 * 25 * @return resetPasswordへの遷移 26 */ 27 @RequestMapping(value = "/resetPassword", method = RequestMethod.GET) 28 public String index(@ModelAttribute MailAddressForm form, Model model) { 29 30 LmsUserRoleEnum[] roles = LmsUserRoleEnum.values(); 31 model.addAttribute("roles", roles); 32 33 LmsUserRoleEnum selected = LmsUserRoleEnum.getEnum(form.getCode()); 34 model.addAttribute("selected", selected); 35 36 return "/password/resetPassword"; 37 } 38}

MailAddressForm.java

1 2package jp.co.sss.lms.form; 3 4import lombok.Getter; 5import lombok.Setter; 6 7public class MailAddressForm { 8 9 @Getter 10 @Setter 11 private String code; 12}

Constants.java

1 2package jp.co.sss.lms.util; 3 4public class Constants { 5 6 public static String CODE_VAL_ROLL_STUDENT = "000"; 7 public static String CODE_VAL_ROLL_TEACHER = "001"; 8 public static String CODE_VAL_ROLL_COMPANY = "002"; 9 public static String CODE_VAL_ROLL_ADMIN = "003"; 10 public static String CODE_VAL_ROLL_TRAINING = "004"; 11}

投稿2022/04/18 13:24

momodx

総合スコア185

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問