From 136f94fbbf427bbdc07753fb230ff275ebafdf14 Mon Sep 17 00:00:00 2001 From: ACHRAF TAITAI <43656331+achraftt@users.noreply.github.com> Date: Mon, 5 Jun 2023 07:59:40 +0200 Subject: [PATCH] =?UTF-8?q?BAEL-5648:=20Thymeleaf=20-=20How=20to=20add=20c?= =?UTF-8?q?hecked=20attribute=20to=20input=20conditio=E2=80=A6=20(#14180)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * BAEL-5648: Thymeleaf - How to add checked attribute to input conditionally * BAEL-5648: Thymeleaf - How to add checked attribute to input conditionally --- .../attribute/CheckedAttributeController.java | 29 +++++++++++++++++++ .../resources/templates/attribute/index.html | 27 +++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 spring-web-modules/spring-thymeleaf-5/src/main/java/com/baeldung/thymeleaf/attribute/CheckedAttributeController.java create mode 100644 spring-web-modules/spring-thymeleaf-5/src/main/resources/templates/attribute/index.html diff --git a/spring-web-modules/spring-thymeleaf-5/src/main/java/com/baeldung/thymeleaf/attribute/CheckedAttributeController.java b/spring-web-modules/spring-thymeleaf-5/src/main/java/com/baeldung/thymeleaf/attribute/CheckedAttributeController.java new file mode 100644 index 0000000000..165e98ac3a --- /dev/null +++ b/spring-web-modules/spring-thymeleaf-5/src/main/java/com/baeldung/thymeleaf/attribute/CheckedAttributeController.java @@ -0,0 +1,29 @@ +package com.baeldung.thymeleaf.attribute; + +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.GetMapping; + +@Controller +public class CheckedAttributeController { + + @GetMapping("/checked") + public String displayCheckboxForm(Model model) { + Engine engine = new Engine(true); + model.addAttribute("engine", engine); + model.addAttribute("flag", true); + return "attribute/index"; + } + + private static class Engine { + private Boolean active; + + public Engine(Boolean active) { + this.active = active; + } + + public Boolean getActive() { + return active; + } + } +} diff --git a/spring-web-modules/spring-thymeleaf-5/src/main/resources/templates/attribute/index.html b/spring-web-modules/spring-thymeleaf-5/src/main/resources/templates/attribute/index.html new file mode 100644 index 0000000000..a7c5b90296 --- /dev/null +++ b/spring-web-modules/spring-thymeleaf-5/src/main/resources/templates/attribute/index.html @@ -0,0 +1,27 @@ + + +
+ +