The get method will prepare the model and send to the "add person" jsp
It will also set the "mode" attribute to be "add" (so add and edit can share same jsp)
When the processSubmit result hasErrors ,mode attribute is gone
How to maintain mode attribute between calls?
@RequestMapping(value="/people/def/add" , method = RequestMethod.GET)
public String personAdd(@ModelAttribute("person") Person person,Model map) {
map.addAttribute("mode", "add");
//DO SOME LOGIC
return "personAdd";
}
@RequestMapping(value="/people/def/add" , method = RequestMethod.POST)
public String processSubmit(@ModelAttribute("person") Person person,BindingResult result) {
personValidator.validate(person, result);
if (result.hasErrors()) {
//MODE ATTRIBUTE IS LOST
return "personAdd";
Request attributes live only for the life of request. So, if you want "mode" back in Post, you may have to submit it back as part of POST, may be by using hidden form control in your web form.
You have to add "@RequestParam("mode") String mode" to your "processSubmit" method to retrieve the value of mode from HTTP POST parameters
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With