Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJ Tan
11,847 PointsPassing boolean value from Thymeleaf to a Controller in Spring Boot
How do I pass a boolean value from Thymeleaf to a Controller in Spring Boot? I have the following Thymeleaf section. I'm referencing defectStatusOpen which is a Boolean.
<div class="row">
<div class="col s12 l8" th:classappend="${#fields.hasErrors('defectStatusOpen')} ? 'error' : ''">
<select th:field="*{defectStatusOpen}">
<!--<option value="" disabled="disabled">Defect Status</option>-->
<!--<option value="true" selected>Status: Open</option>
<option value="false">Status: Closed</option>-->
<option value="" disabled="disabled">Category Color</option>
<option style="color:#59b3b3">Aqua</option>
</select>
</div>
</div>
When I load the form, I get the following error
2017-08-30 12:50:00.912 ERROR 886 --- [nio-8080-exec-2] org.thymeleaf.TemplateEngine : [THYMELEAF][http-nio-8080-exec-2] Exception processing template "defect/form": Error during execution of processor 'org.thymeleaf.spring4.processor.attr.SpringOptionFieldAttrProcessor' (defect/form:37)
2017-08-30 12:50:00.921 ERROR 886 --- [nio-8080-exec-2] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateProcessingException: Error during execution of processor 'org.thymeleaf.spring4.processor.attr.SpringOptionFieldAttrProcessor' (defect/form:37)] with root cause
java.lang.IllegalArgumentException: A null value cannot be assigned to a primitive type
I don't understand how it can still be primitive if I've declared in my Entity with private Boolean defectStatusOpen = true;