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 trialSergei Makarov
13,839 PointsUsing Thymeleaf-Form Tempalte to set Values to Fields of Class
Sorry, but I really do not understand, how works a thymeleaf processing in background. I mean, as long as our Class Category does have only one constructor without any parameters, don't we need to use setName method in the field of input tag (don't really know, if it possible, to use methods in Templates, but eventually).
...
<form th:action="@{/categories}" method="post" th:object="${category}">
...
<div class="col s12 l8"> <input type="text" th:field="*{name}" placeholder="Category Name"/> </div>
I just mean. how does thymeleaf know to use setName method, instead of using a getName() for example? Is it cause of POST.method? I wouldn't confused, if we had a constructor with field Name and Color, but as long as we don't, it seems to be strange for me.
Aidan Melendez
5,637 PointsAidan Melendez
5,637 PointsHey Sergei, I know I may be late in answering your question. But for anyone who may find this question and was wondering the same thing, it is as simple as Thymeleaf calling the category's objects "getName()" function.
for anyone who would like to read further on the subject, here is a link for the Thymeleaf documentation!
http://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html#using-thtext-and-externalizing-text