• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

how to bind thymeleaf checkbox value to boolean variable in spring ?

 
Ranch Hand
Posts: 50
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to bind checkbox value to spring bean as boolean. when use check the checkbox then it will take as true value otherwise false.

This is what I have done so far. I am using `Kotlin` as programming language and `Thymeleaf` with the html page.

html page


this is the bean,

this is the rest controller


the request is hit the controller successfully but how can I bind the value true when the checkbox is check and false otherwise.

Thanks in advance.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One possible way would be to utilize javascript to change the value of the checkbox on click.
One other option is to utilize two different radio buttons and use the th:field="isPresent" option to specify that return attribute is named "isPresent".

I'm not sure if your stuff is working, but I don't see that you've assigned an object to your form. You can include th:object="AttendanceJson" in your 'form' HTML element.
reply
    Bookmark Topic Watch Topic
  • New Topic