1

This is my JSP code

<form:form action="multiplebuttons.html"  commandName="buttonForm">
<table>
<tr>
        <td width="7%">Name:</td>
        <td width="11%"><form:input path="name" /></td><td width="82%"><form:errors cssStyle="color:red" path="name"/></td>                 
    </tr>
<tr>
        <td><input type="submit" value="update" /></td><td><input type="submit" value="save" /></td>
    </tr>
</table>

</form:form>

This is my Controller code

@Autowired
@Qualifier("formValidator")
private Validator validator;

@InitBinder
private void initBinder(WebDataBinder binder) {
    binder.setValidator(validator);
}

@RequestMapping(value="/views", method = RequestMethod.GET)
public ModelAndView getdata() {
    System.out.println("do something");
    ModelAndView model = new ModelAndView("views");

    model.addObject("name", "Girish");
    return model;
}

@RequestMapping(value="/multiplebuttons", method = RequestMethod.GET)
public String showForm(Map model) {
    System.out.println("Show form");
    ButtonForm Form = new ButtonForm();
    model.put("buttonForm", Form);
    return "multiplebuttons";
}

@RequestMapping(method = RequestMethod.POST)
public String processForm(  @Validated  ButtonForm buttonForm, BindingResult result,
        Map model) {
    System.out.println("Processing..........");             

    if (result.hasErrors()) {
        System.out.println("Has errors");
        return "multiplebuttons";
    }
    return "redirect:views";
}

@RequestMapping("/{name}")
public String editItem(@PathVariable("name") String name, Model model){
    ButtonForm form = new ButtonForm();

    form.setName(name);

    model.addAttribute("buttonForm", form);
    return "multiplebuttons";
}

Please help. Can you please tell me why processForm method is not triggered?

Thanks in advance

2
  • are you getting an exception? Commented Oct 20, 2014 at 10:10
  • no simply the method is not triggered. Commented Oct 20, 2014 at 11:29

1 Answer 1

1

you should modify method processForm():

@RequestMapping(value="/multiplebuttons", method = RequestMethod.POST)
public String processForm(  @Validated  ButtonForm buttonForm, BindingResult result,
        Map model) {
    System.out.println("Processing..........");             

    if (result.hasErrors()) {
        System.out.println("Has errors");
        return "multiplebuttons";
    }
    return "redirect:views";
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.