So my problem is that I want to pull out a single record form my database (mysql-workbench). So when you are on the homepage you can see all the records from the database, what I want is when you press the button "read more" on a record you go into a new html page depening on want record you chose to read more on an here want to pull a single record out by using the @pathvarable. Hope I makes sense.
So the problem I think must be in the controller with @GetMapping ("/faellesskab/{faellesskabNavn}") and in the html file where I use it wrong.
So I have no problem in seeing all the records from the database, but when I want to pull out one I have the problem in the html file th:field="*{faellesskabNavn}.
@Controller
public class FaellesskabController {
@Autowired
FaellesskabServiceI fs;
@Autowired
BegivenhedServiceI bs;
@GetMapping ("/faellesskaber")
public String faellesskaberForm(Model model) throws Exception {
model.addAttribute("faellesskablist",fs.getFaellesskabList());
model.addAttribute("faellesskaber", new Faellesskab());
return "faellesskaber";
}
@GetMapping ("/faellesskab/{faellesskabNavn}")
public String faellesskabNavn(Model model, @PathVariable String faellesskabNavn) throws Exception {
Faellesskab faellesskab = fs.getSingleFaelleskab(faellesskabNavn);
System.out.println(faellesskab);
model.addAttribute("faellesskabSingle",faellesskab);
return "faellesskab";
}
}
HTML file
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8" />
<title>Fællesskaber</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
</head>
<body>
<!-- Page Content -->
<div class="container">
<div class="col-md-50">
<h1 class="my-4">Velkommen til fællesskaberne</h1>
<!-- Marketing Icons Section -->
<div class="row">
<!-- <form action th:action="@{faelleskab}" th:object="${faellesskabNavn}" method="get"> -->
<div class="col-lg-4 mb-4" th:each="Faellesskaber : ${faellesskablist}">
<div class="card h-100">
<h4 class="card-header" th:text="${Faellesskaber.faellesskabNavn}"></h4>
<div class="card-body">
<p class="card-text" th:text="${Faellesskaber.faellesskabBeskrivelse}"></p>
</div>
<div class="card-footer">
<a href="/faellesskab" class="btn btn-primary">Læs mere</a>
<!-- <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#Beskrivelse"> -->
</div>
</div>
</div>
</div>
</div>
</div>
<div id="contentwrapper">
<form action="#" th:action="@{/faellesskab}" th:object="${faellesskabSingle}" method="get">
<p>Fællesskab navn: <input type="text" required="required" th:field="*{faellesskabNavn}"/></p>
<p><input type="submit" value="Submit" /> <input type="reset" value="Reset" /></p>
</form>
<br>
<button type="button" class="btn btn-primary btn-sm" data-toggle="modal" data-target="#Createpatient">Opret patient</button></td>
</div>
</body>
</html>
The error message I get. Error during execution of processor 'org.thymeleaf.spring5.processor.SpringInputGeneralFieldTagProcessor' (template: "faellesskaber" - line 38, col 68)