こんにちは、thymeleafを使ってテキストボックスに入力するページが有り、
テキストボックスに入力、変更された値をボタンを押すことで/confirmというurlにpostして
決定画面のように表示させたいです。
現在最初の入力フォームを表示させることは出来ているのですが、ページ遷移させると遷移先で
500エラーが出るのですが
Exception parsing document: template="confirm", line 6 - column 3
このthymeleafで作成されたconfirm.htmlの6行めでおかしいと思うところがなく、改善すべきところがわかりません。
初心者なので変なところにがあるかもしれません、解決策がわかる方いらっしゃいましたらよろしくお願いします。
以下コードです
Java
1@Controller 2public class HelloController { 3 @RequestMapping(value = "/", method = RequestMethod.GET) 4 public ModelAndView index(Person personFormData) { 5 ModelAndView mav = new ModelAndView(); 6 mav.setViewName("index"); 7 List<Person> personList = new ArrayList<Person>(); 8 9 Person personA = new Person(); 10 personA.setName("A"); 11 personA.setAge(33); 12 personA.setHobby("プログラミング"); 13 personList.add(personA); 14 15 Person personB = new Person(); 16 personB.setName("B"); 17 personB.setAge(32); 18 personB.setHobby("書道"); 19 personList.add(personB); 20 21 Person personC = new Person(); 22 personC.setName("C"); 23 personC.setAge(20); 24 personC.setHobby("トマト栽培"); 25 personList.add(personC); 26 27 mav.addObject("personList", personList); 28 29 //フォーム上で扱うデータはpersonのリストではなくひとつのPersonFormと考える。 30 PersonForm personFrom = new PersonForm(); 31 personFrom.setPersonList(personList); 32 mav.addObject("personFormData", personFrom); 33 34 return mav; 35 } 36 37 @RequestMapping(value = "/confirm", method = RequestMethod.POST) 38 public String confirm (@ModelAttribute PersonForm personFormData, Model model){ 39 model.addAttribute("personFormData", personFormData); 40 return "confirm"; 41 } 42 43} 44 45____________________________________________ 46<form> 47 48public class PersonForm { 49 public PersonForm() { 50 this.personList = new ArrayList<Person>(); 51 } 52 private List<Person>personList; 53 public List<Person>getPersonList(){ 54 return personList; 55 } 56 public void setPersonList(List<Person>personList) { 57 this.personList = personList; 58 } 59} 60
HTML
1//最初に表示させる画面 2<!DOCTYPE HTML> 3<html xmlns:th="http://www.thymeleaf.org"> 4<head> 5<title>Top page</title> 6<meta http-equiv="Content-Type" 7 content="text/html;charset=UTF-8"/> 8<style> 9body { font-size:13pt; color:gray; margin:5px 25px; } 10pre { font-size:13pt; color:gray; padding:5px 10px; border:1px; solid gray; } 11</style> 12</head> 13<body> 14 <form th:action="@{/confirm}" th:object="${personFormData}" method="post"> 15 <table id="personList"> 16 <tr> 17 <th>NAME</th> 18 <th>AGE</th> 19 <th>HOBBY</th> 20 </tr> 21 <tr th:each="tmpPerson, stat : *{personList}"> 22 <td th:text="${tmpPerson.name}"></td> 23 <td th:text="${tmpPerson.age}"></td> 24 <!-- __${stat.index}__ ←プリプロセッシング --> 25 <td><input type="text" class="form-control" th:value="${tmpPerson.hobby}" th:field="*{personList[__${stat.index}__].hobby}" /></td> 26 </tr> 27 </table> 28 <button type="button" id="addrow" onclick="addList();">+</button> 29 <button type="submit" id="confirm" >confirm</button> 30 </form> 31</body> 32</html>
HTML
1//決定画面として表示したい部分 2<!DOCTYPE html> 3<html xmlns:th="http://www.thymeleaf.org"> 4<head> 5<meta charset="UTF-8"> 6<title>Confirm</title> 7</head> 8<body> 9 <table id="personList"> 10 <tr> 11 <th>NAME</th> 12 <th>AGE</th> 13 <th>HOBBY</th> 14 </tr> 15 <tr th:each="tmpPerson, stat : *{personList}"> 16 <td th:text="${tmpPerson.name}"></td> 17 <td th:text="${tmpPerson.age}"></td> 18 <td th:text="${tmpPerson.hobby}"/></td> 19 </tr> 20 </table> 21</body> 22</html>
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。