radio button binding to nested object attribute

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

radio button binding to nested object attribute

sangeetabellara
I am using Spring boot with thymeleaf.
FORM BACKING BEAN:
public class TermReportForm {
    private long gradeid;
    private String gradenumber;
    private Grading grading;}

NESTED OBJECT GRADING IN FORM BACKING BEAN WHICH HAS TO BE POPULATED BY USER INPUT:
public class Grading {    
    private String activity;
    private int performance;}


MY FORM:
<form class="form-group" th:action="@{/createtermreportforstudent}" th:object="${trf}" method="post"> 
      <div class="form-group" id="TextBoxDiv0">
     <th:block th:id="grading" >
               <input th:id="activity" th:name="activity"  th:field="*{grading.activity}"/>
               <label class="radio-inline">
               <input th:name="performance" th:value="1" type="radio" th:field="*{grading.performance}"/>1</label>
               <label class="radio-inline">
               <input th:name="performance" th:value="2" type="radio" th:field="*{grading.performance}"/> 2 </label>
               <label class="radio-inline">
                  <input th:name="performance" th:value="3" type="radio" th:field="*{grading.performance}"/> 3 </label> 


      </div>
     <button type="submit" class="btn btn-primary">Save</button> 
     </form>

The problem is that the attribute "performance" (radio button) in the nested object "grading" is not getting populated with the user choice. On the other hand, the attribute "activity" (text input) of the nested object is getting populated just fine. Where I am going wrong?