0

I have managed to make a modelAndView in my controller doing what Im expecting from the ui, but sometimes I need to test it via post man so when I tried the model attribute is always null, can someone explain what is happening exactly?

here is the controller that im using:

@Controller
public class LoginController extends AuthenticationBase {

    @Autowired
    private AuthenticationInterfaceImpl authentication;

    Logger logger = LoggerFactory.getLogger(LoginController.class);

    @GetMapping("/login_form")
    public ModelAndView login(@ModelAttribute LoginForm loginForm) {
        return new ModelAndView("index");
    }

    @PostMapping("/login_form")
    public ModelAndView login(HttpServletRequest request, HttpServletResponse response,
        @ModelAttribute LoginForm loginForm, BindingResult   result) {
        LoginInfo loginInfo;
    try {
        loginInfo = authentication.userLogin(loginForm.getUserName(), loginForm.getPassword());
        if (loginInfo.getNewPasswordRequired()) {
            return new ModelAndView("change_password", "change_password", loginForm.getUserName());
        } else {
            UserInfo userInfo = new UserInfo(loginInfo.getUserName(), loginInfo.getEmailAddr(), "");
            return new ModelAndView("application", "application", userInfo);
        }
    } catch (Exception e) {
        logger.error(e.getMessage());
    }
        return new ModelAndView("index", "authenticationError", "Password or user name error!");

    }
}
Khaled
  • 529
  • 8
  • 19
  • I doubt the model is `null` it can be empty. When using Postman make sure you are sending a form and not a json request body. – M. Deinum Feb 13 '19 at 07:10
  • Thanks @M.Deinum I just noticed that I have to send it a form and not json – Khaled Feb 13 '19 at 14:41

0 Answers0