Checkbox disappear while using th:field in thymeleaf+Spring+JPA. Please help urgently

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Checkbox disappear while using th:field in thymeleaf+Spring+JPA. Please help urgently

sanjibgogoi
Hi,

I am trying to generate checkbox dynamically, But when i am using th:field value checkbox is disappearing. Please help.

HTML Snippet:
<li th:each="authorize: ${roles_checkbox}">
                                                        <div class="col s6 m4" style="padding-top: 15px;">
                                                                <p>
                                                                 
                                                                         <label > <input th:type="checkbox" name="authoriseName"
                                                                                th:value="${authorize.id}"  th:field="*{roles}"  > 
                                                                               

                                                                        </label>
                                                                </p>
                                                        </div>

                                                </li>


Controller:

@GetMapping({ "/admin_dashboard" })
        public String adminDashboard(Model model) {
                model.addAttribute("users", new Users());
                List<Roles> roles = new ArrayList<Roles>();
                for(int i=0; i<roleRepository.count();i++) {
                        roles.add(new Roles(roleRepository.findAll().get(i).getId(),roleRepository.findAll().get(i).getName().toString()));
                }
                model.addAttribute("roles_checkbox", roles);
                return "admin_dashboard";
        }

        @PostMapping("/admin_dashboard")
        public String registration(@ModelAttribute("users") Users users, BindingResult bindingResult) {

                if (bindingResult.hasErrors()) {
                        return "registration";
                }

                userService.save(users);

                return "redirect:/welcome";
        }

Image before th:field

<nabble_img src="without_field.jpg" border="0"/>


Image after adding th:field in checkbox input type.




Please help!!!!

Thanks in advance

Reply | Threaded
Open this post in threaded view
|

Re: Checkbox disappear while using th:field in thymeleaf+Spring+JPA. Please help urgently

sanjibgogoi
If i don't use th:field in input type checkbox then checkbox appeared.

Screenshot attached
Reply | Threaded
Open this post in threaded view
|

Re: Checkbox disappear while using th:field in thymeleaf+Spring+JPA. Please help urgently

sanjibgogoi
In reply to this post by sanjibgogoi
Please help me out:

when i put th:field tag in my input type checkbox, checkbox disappear.

I am stuck. Please help
Reply | Threaded
Open this post in threaded view
|

Re: Checkbox disappear while using th:field in thymeleaf+Spring+JPA. Please help urgently

Reiju
Try to add this script (jquery) to ur page

$(document).ready(function () {
        $("input[type='checkbox']").each(function () {
                $(this).next().insertBefore($(this));
        });
});

Sometimes hidden fields created by thymeleaf has wrong position due to ur css-framework.