i new spring , need little guidance. have through spring tutorials, cannot find looking for. want know best way handle scenario:
- user goes index page , presented form.
- user fills out forms , submits new url (passes client side validation)
- during spring validation of form object, detect errors
- redirect user index page affected fields highlighted
i assuming correct flow situation. if not, please tell me otherwise. if correct flow, how pass binding/validation errors template?
in situation follow post/redirect/get pattern flow. when server side validation fails (result.haserrors()
) not redirect display index page again. spring handles passing errors template. display errors use function of template engine supports spring mvc (for example display errors in jsp - <form:errors path="*" element="div" />
).
@controller public class mycontroller { @requestmapping(value="/index.html", method=requestmethod.get) public string display(@modelattribute myform myform){ return "index"; } @requestmapping(value="/process.do", method=requestmethod.post) public string processform(@modelattribute @validated myform myform, bindingresult result) { if(result.haserrors()){ return display(myform); } return "redirect:/processed.html"; } }