mardi 18 décembre 2018

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

Im trying to populate a checkboxes from a list getting from the controller in spring-jsp. Im getting the list from a service and then it is added to the model as an attribute. But im finding it hard to access and display it as checkboxes in the view. So im getting the above error in the log. What could have been gone possibly wrong?

The controller :

    @RequestMapping(value = "/user-roles", method = RequestMethod.GET)
    public String viewRoles(Model model) {

    List<Permission> permissionsList;
    permissionsList = roleService.getAllPermission();

    model.addAttribute("permissions", permissionsList);
    return "user_roles";
}

    @RequestMapping(value = "/roles/addrole", method = RequestMethod.POST)
    public ModelAndView saveEmployee(@ModelAttribute("addrole") SystemRole role, ModelMap model) {

    roleService.saveSystemRole(role);
    model.addAttribute("user", new SystemRole());
    return new ModelAndView("user_roles");
}

the view :

           <div class="modal-body">
            <form:form method="post" modelAttribute="addrole" action="/roles/addrole">
                <div class="form-group">
                    <label for="role-name" class="col-form-label">Role Name</label>
                    <input type="text" class="form-control" id="role-name">
                </div>
                <div class="form-group">
                    <label class="col-form-label">Permissions</label>

                    <div class="check-box" style="padding-left: 20px">
                        <c:forEach items="${permissions}" var="oo">
                            <form:checkbox id="${oo.id}" label="${oo.name}" value="${oo.id}" path="permissionList"/>
                        </c:forEach>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                    <button type="submit" class="btn btn-primary">Submit</button>
                </div>
            </form:form>
        </div>




Aucun commentaire:

Enregistrer un commentaire