samedi 28 août 2021

Thymeleaf th:field inside th:each is not working

Im trying to render an exam page with my miniproject using this codes

public class ExamModel {

private String question;
private String answer;

/with setters&getters

}

This Controller return ArrayList of ExamModel

@GetMapping(value="/generateexam") public String generateExam(Model model){

    model.addAttribute("question", examService.generateQuestion());
  
   
    return "exam";
}

This is my html

           <form th:action="@{/getresult}" th:object="${question}" method="post">
                <table>
                    <tr th:each="q, i: ${question}">
                           <td th:text="${q.question}"></td> 
                           <td><input type="text" th:field="*{question[__${i.index}__].answer}" value="answer"/></td>
                    </tr>
                </table>
                <input type="submit" value="Result">
           </form>
      
  

in the browser this is the error message that im getting

Caused by: org.springframework.beans.NotReadablePropertyException: Invalid property 'question[0]' of bean class [java.util.ArrayList]: Bean property 'question[0]' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?




Aucun commentaire:

Enregistrer un commentaire