I am relatively new to Spring and would like my user to be able to save the true or false value into the DynamoDB table. It should come from the class working together with Thymeleaf form. This form has a checkbox in it which supposed to be true (checked) or false (unchecked). The issue is that each time I try to do it with th:checked it only saves false into the database, whereas th:field gives the "Whitelabel error page" in AWS Elastic Beanstalk.
Student (shorter version):
public class Student {
private boolean isPresent;
///Getters.
public boolean isPresent() {return isPresent;}
//Setters.
public void setPresent(boolean isPresent) {this.isPresent = isPresent;}
}
StudentItems (shorter version):
@DynamoDbBean
public class StudentItems {
private boolean isPresent;
//Constructor.
public StudentItems()
{
}
///Getters.
public boolean isPresent() {return isPresent;}
//Setters.
public void setPresent(boolean isPresent) {this.isPresent = isPresent;}
}
StudentController:
@Controller
public class StudentController {
@Autowired
private DynamoDBEnhanced dde;
@Autowired
private SMSNotification msg;
@GetMapping("/")
public String studentTrackForm(Model model) {
model.addAttribute("student", new Student());
return "student";
}
@PostMapping("/student")
public String studentSubmit(@ModelAttribute Student student) {
//Stores data in an Amazon DynamoDB table.
dde.insertDynamoItem(student);
//Sends a notification to the number specified about
//newly added student.
msg.sendMessage(student.getStudentName(),
student.getStudentSurname(),
student.getStudentID(),
student.getStudentYear(),
student.isPresent());
return "result";
}
}
HTML form page (shorter version):
<form action="#" th:action="@{/student}" th:object="${student}" method="post">
<div class="form-group">
<p>Student ID: <input type="text" class="form-control" th:field="*{studentID}" /></p>
</div>
<div class="form-group">
<p>Present:<input type="checkbox" class="form-control" th:checked="*{isPresent}" /></p>
</div>
<p><input type="submit" value="Submit" /> <input type="reset" value="Reset" /></p>
</form>
DynamoDB table result: DynamoDB table result
I have already tried to use:
@DynamoDBTyped(DynamoDBAttributeType.BOOL)
@DynamoDBAttribute(attributeName = "value")
and the many related links such as the one below but nothing seems to work unless I have missed an important step: Thymeleaf - How to add checked attribute to input conditionally
Please let me know if you know of any solution using either boolean
or Boolean
and the Thymeleaf form. In another case, I will just try to solve this issue using JavaScript (would prefer not to due to project specs).
Thank you in advance.