0

I want to edit a row of a table in another html page. I have a beginner with thymeleaf and Spring MVC...

profilesAll.html

enter image description here

but, i have this error : org.thymeleaf.exceptions.TemplateProcessingException: Error during execution of processor 'org.thymeleaf.spring5.processor.SpringInputRadioFieldTagProcessor' (template: "profilsAll" - line 39, col 26) ....

Caused by: java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'profil' available as request attribute

ProfilsAll.html :

<form th:action="@{/profiles/update}" th:object="${profil}" method="POST">
    <table border="1">
        <thead>
            <tr> 
                <th>Select</th> 
                <th>UID</th>
                <th>SIP</th>
                <th>enterpriseVoiceEnabled</th>
                <th>voicePolicy</th>
                <th>dialPlan</th>
                <th>samAccountName</th>
                <th>exUmEnabled</th>
                <th>exchUser</th>
                <th>objectClass</th>
                <th>statusProfile</th>
            </tr>
        </thead>
        <tbody>
            <tr th:if="${skypeProfiles.empty}">
                <td colspan="2"> No skype profile available </td>
            <tr th:each="skypeProfile, profile:${skypeProfiles}">
                <td>
                    <input type="radio" th:field="*{profile}" th:value="${profile}" />
                </td>
                <td th:text=${skypeProfile.collaboraterId}>UID</td>
                <td th:text=${skypeProfile.SIP}>SIP</td>
                <td th:text=${skypeProfile.enterpriseVoiceEnabled}>enterpriseVoiceEnabled</td>
                <td th:text=${skypeProfile.voicePolicy}>voicePolicy</td>
                <td th:text=${skypeProfile.dialPlan}>dialPlan</td>
                <td th:text=${skypeProfile.samAccountName}>samAccountName</td>
                <td th:text=${skypeProfile.exUmEnabled}>exUmEnabled</td>
                <td th:text=${skypeProfile.exchUser}>exchUser</td>
                <td th:text=${skypeProfile.objectClass}>objectClass</td>
                <td th:text=${skypeProfile.statusProfile}>statusProfile</td>
            </tr>   
        </tbody>
    </table>
    <button type="submit" value ="Edit">Edit</button>
</form>

Controller :

@PostMapping("profiles/update")
public String profilesUpdate(@ModelAttribute("profil") SkypeProfileSearchBean skypeProfile) {
    
    System.out.print("skypeProfile id "+skypeProfile.getCollaboraterId());
    return "profilsUpdate";
}

This code is problematic but I did not find the solution :

<input type="radio" th:field="*{profile}" th:value="${profile}" />

Thank you very much for your help

Lakshan
  • 1,404
  • 3
  • 10
  • 23
Jutige
  • 5
  • 2

1 Answers1

0

You don't need to have two instances of skypeProfiles to use one in object and display one. Just having one instance would be enough. Ref - https://www.baeldung.com/spring-boot-crud-thymeleaf

replace <tr th:each="skypeProfile, profile:${skypeProfiles}"> with <tr th:each="skypeProfile : ${skypeProfiles}">

and <input type="radio" th:field="*{profile}" th:value="${profile}" /> with <input type="radio" th:field="*{skypeProfile}" th:value="${skypeProfile}" />

Patrick
  • 1,635
  • 2
  • 13
  • 23
  • Thanks Patrick for your answer but i have the same error... – Jutige Aug 27 '20 at 14:21
  • First is your table getting printed ? Show your get mapping - it should first have all values for the profile. – Patrick Aug 27 '20 at 14:28
  • Possibly a duplicate of https://stackoverflow.com/questions/53951501/how-to-use-input-radio-button-with-thymeleaf-and-spring-mvc – Patrick Aug 27 '20 at 14:33
  • Also could be a possible duplicate of https://stackoverflow.com/questions/53743806/error-during-execution-of-processor-org-thymeleaf-spring5-processor-springinput – Patrick Aug 27 '20 at 14:38