fix: resolve HTMX POST CSRF token and unhandled ViewResolver 500 error
This commit is contained in:
+1
@@ -28,6 +28,7 @@ public class AdminPreInscriptionController {
|
||||
}
|
||||
|
||||
@PostMapping("/{id}/valider")
|
||||
@ResponseBody
|
||||
public String valider(@PathVariable Long id, HttpServletResponse response) {
|
||||
Adherent adherent = preInscriptionService.validerPreInscription(id, null);
|
||||
response.setHeader("HX-Trigger", "refreshBadge");
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
<script src="https://unpkg.com/htmx.org@1.9.11"></script>
|
||||
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
|
||||
<style> body { font-family: 'Inter', sans-serif; } </style>
|
||||
<meta name="_csrf" th:content="${_csrf.token}"/>
|
||||
<meta name="_csrf_header" th:content="${_csrf.headerName}"/>
|
||||
</head>
|
||||
<body class="bg-gray-50 text-gray-900 flex h-screen overflow-hidden">
|
||||
<!-- Sidebar -->
|
||||
@@ -44,12 +46,11 @@
|
||||
<div class="text-xs text-gray-500" th:text="${pre.email}"></div>
|
||||
</td>
|
||||
<td class="py-4 px-6 text-right space-x-2">
|
||||
<button th:hx-post="@{/admin/pre-inscriptions/{id}/valider(id=${pre.id})}"
|
||||
<button th:attr="hx-post=@{/admin/pre-inscriptions/{id}/valider(id=${pre.id})}"
|
||||
class="bg-blue-600 text-white px-3 py-1.5 rounded hover:bg-blue-700 transition-colors">
|
||||
Créer la fiche
|
||||
</button>
|
||||
<button th:hx-post="@{/admin/pre-inscriptions/{id}/rejeter(id=${pre.id})}"
|
||||
th:hx-target="'#pre-' + ${pre.id}"
|
||||
<button th:attr="hx-post=@{/admin/pre-inscriptions/{id}/rejeter(id=${pre.id})}, hx-target=|#pre-${pre.id}|"
|
||||
hx-swap="outerHTML"
|
||||
hx-confirm="Confirmer le rejet du dossier ?"
|
||||
class="bg-red-50 text-red-600 border border-red-200 px-3 py-1.5 rounded hover:bg-red-100 transition-colors">
|
||||
@@ -62,5 +63,12 @@
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<script>
|
||||
document.body.addEventListener('htmx:configRequest', function(evt) {
|
||||
evt.detail.headers[document.querySelector('meta[name="_csrf_header"]').content] =
|
||||
document.querySelector('meta[name="_csrf"]').content;
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user