I receive following message when I try to submit my form. I am trying to use select forms and this worked when I just used input forms. What am i doing wrong?
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Sun Dec 01 11:49:08 CET 2019 There was an unexpected error (type=Not Found, status=404).
No message available
The controller
@Controller
public class SubmissionController {
private final CurrencyService currencyService;
@Autowired
public SubmissionController(CurrencyService currencyService) {
this.currencyService = currencyService;
}
@GetMapping("/")
public String converterForm(Model model) {
model.addAttribute("currencies", currencyService.getAllCurrencies());
model.addAttribute("exchange", new FormObject());
return "index";
}
@PostMapping("/result")
public String convertSubmit(@ModelAttribute FormObject formObject, Model model) {
model.addAttribute("result", currencyService.conversion(formObject.getFrom(),formObject.getTo(), formObject.getAmount()));
return "result";
}
}
The Form page
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head lang="en">
<meta http-equiv="Content-Type" charset="UTF-8">
<title>Title</title>
</head>
<body>
<h1>Currency Converter</h1>
<form action="#" th:action="@{/converter}" th:object="${exchange}" method="post">
<p>Currency from: <select th:field="*{from}">
<option th:each="currency: ${currencies}"
th:value="${currency.id}"
th:utext="${currency.id}"></option>
</select></p>
<p>Currency to: <select th:field="*{to}">
<option th:each="currency: ${currencies}"
th:value="${currency.id}"
th:utext="${currency.id}"></option>
</select></p>
<p>Amount : <input type="text" th:field="*{amount}" /></p>
<p><input type="submit" value="Convert" /> <input type="reset" value="Reset" /></p>
</form>
</body>
</html>
The result output page
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Getting Started: Handling Form Submission</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<h1>Result</h1>
<p th:text="'content: ' + ${result}" />
<a href="/converter">Submit another message</a>
</body>
</html>
Aucun commentaire:
Enregistrer un commentaire