Skip to content
Advertisement

Retrieving a boolean value from webpage using Thymeleaf + Spring boot with Java

JavaScript

Above is my Super Human model. Please take note of the boolean variable named hero.

JavaScript

Above is the controller method I am using to retrieve form data via servlet request. The commented portions are to be replaced with actual working code, once discovered.

JavaScript

Above is the final piece. This is a excerpt from HTML form submission page for adding the super human object into a SQL database. The issue I am currently faced with is this; I am presenting two options:

1.) You’re either a Hero (The boolean value for this is TRUE)

2.) You’re either a Villian (The boolean value for this is FALSE)

I’m unsure how to return boolean data through html input. I’ve googled this question and have read through the thymeleaf docs and have not been able to find the answer for myself.

JavaScript

This is the portion I am working on, I’ve tried using th:field ${SuperHuman.hero} and setting the option values to th:value=”true” and false, respectively, but I’ve only received errors in return.

I just want to know if there is a way to return a boolean true or false through an input field where the user can select if they are either a hero or villian and receive said data in java where i can submit it into an SQL database.

Advertisement

Answer

you must change your code like below

JavaScript
Advertisement