Note that there are some explanatory texts on larger screens.

plurals
  1. POSpring multiple @ModelAttribute methods in the same @Controller
    primarykey
    data
    text
    <p>I have a page with two different forms (with two different submits) on Spring MVC 3, and I have a problem with @ModelAttribute methods. When I have two on the same controller, they are not always executed making the model to be NULL.</p> <p>The code:</p> <pre><code>@Controller @RequestMapping(value = "/session/admin/permission/{userId}") public class PermissionController { @Autowired private UserManager userManager; @ModelAttribute("passwordValidation") private PasswordValidation getPasswordModel(){ return new PasswordValidation(); } @ModelAttribute("user") private User getUserModel(@PathVariable("userId") String userId){ //This is not executed return userManager.getUser(userId); } @ModelAttribute("permissionsAvailable") private PermissionsAvailable getPermissionsModel(@ModelAttribute("user") User user) { return new PermissionsAvailable(); } @RequestMapping(method = RequestMethod.GET) public String adminPermission(){ return "/security/permission"; } @RequestMapping(method = RequestMethod.POST, params="changeRoles") public String modifyPermission(@ModelAttribute("permissionsAvailable") PermissionsAvailable permissions, HttpServletRequest request, @ModelAttribute("user") User user, final RedirectAttributes redirectAttributes){ //Modify something } @RequestMapping(method = RequestMethod.POST, params="changePassword") public String modifyPassword( @ModelAttribute("passwordValidation") PasswordValidation passwordValidation, @ModelAttribute("user") User user, HttpServletRequest request, BindingResult bindingResult, final RedirectAttributes redirectAttributes){ return "newpage"; } } </code></pre> <p>Don't know why, sometimes everything goes ok and every method is executed, but sometimes they are not executed.</p> <p><strong>UPDATE:</strong> I have two different controllers with the same problem so it must be an error on Spring or something I'm doing wrong.</p> <p>Thanks.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload