I get this error only on certain situations. What I’m coding is a registration form, here is the basic code:
@Controller
@SessionAttributes("registrationForm")
@RequestMapping(value = "/registration")
public class RegistrationController
{
@Autowired
private RegistrationValidator registrationValidator;
@RequestMapping(method = RequestMethod.GET)
public String setupForm(Model model) throws Exception
{
return setupForm(model, new RegistrationForm());
}
@RequestMapping(method = RequestMethod.POST)
public String submitForm(@ModelAttribute("registrationForm") RegistrationForm registrationForm,
Model model,
BindingResult result,
SessionStatus sessionStatus) throws Exception
{
registrationValidator.validate(registrationForm, result);
if(result.hasErrors())
{
return setupForm(model, registrationForm);
}
else
{
// Do stuff
sessionStatus.setComplete();
return "redirect:success";
}
}
private String setupForm(Model model, RegistrationForm registrationForm) throws Exception
{
model.addAttribute("currentYear", Calendar.getInstance().get(Calendar.YEAR));
model.addAttribute("registrationForm", registrationForm);
return "registration";
}
The form:
<form:form method="POST" modelAttribute="registrationForm">
...
</form:form>
The very strange problem I have, is that if I clear the session data and I go straight to /registration, the whole registration process works perfectly. But when I call a page that is mapped in another controller first (i.e. home page), then I get the error specified in the title.
Can anyone help me?
Thank you.
Adding this solved the problem: