Win a copy of JDBC Workbook this week in the JDBC and Relational Databases forum
or A Day in Code in the A Day in Code forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • salvin francis
  • fred rosenberger

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

Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • 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.
Posts: 1
  • Mark post as helpful
  • send pies
  • 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.
straws are for suckers. tiny ads are for attractive people.
Devious Experiments for a Truly Passive Greenhouse!
    Bookmark Topic Watch Topic
  • New Topic