0

I am a newbie to advanced java and learning Spring framework. I found one tutorial

http://netbeans.org/kb/docs/web/quickstart-webapps-spring.html

In the code below

package contoller;

import java.net.BindException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.portlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;
import service.HelloService;
/**
*
* @author Manish
*/
public class HelloController extends SimpleFormController {

public HelloController() {
setCommandClass(Name.class);
setCommandName("name");
setSuccessView("helloView");
setFormView("nameView");
}
 private HelloService helloService;
 public void setHelloService(HelloService helloService) {
 this.helloService = helloService;
  }

@Override          // Error Method does not override or implment a method of supertype
protected ModelAndView onSubmit(
        HttpServletRequest request,
        HttpServletResponse response,
        Object command,
        BindException errors) throws Exception {

    Name name = (Name) command;
    ModelAndView mv = new ModelAndView(getSuccessView());
    mv.addObject("helloMessage", helloService.sayHello(name.getValue()));
    return mv;
  }

How can I fix this problem?

Regards.

Swapnil
  • 8,201
  • 4
  • 38
  • 57
Manish
  • 3,341
  • 15
  • 52
  • 87
  • 1
    Can you post the whole class? – ElderMael Dec 22 '12 at 04:48
  • What is use of annotation in framework? – Manish Dec 22 '12 at 04:57
  • @override is not spring annotation. It just indicates that method is an overriden method from super class. Your super class `SimpleFormController ` dont have a method with signature `protected ModelAndView onSubmit( HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception` – Subin Sebastian Dec 22 '12 at 04:59
  • If i remove this, will it be ok to use. I think it will throw an error. If there is no method in this class then we should not override it. – Manish Dec 22 '12 at 05:02
  • 1
    Please take a look at: http://stackoverflow.com/questions/4734259/spring-simpleformcontroller-in-3-0 –  Dec 22 '12 at 05:28

1 Answers1

1

Error: Method does not override or implment a method of supertype

This is not related to Spring. It says in your SimpleFormController class there is no method onSubmit.

Add this method to your SimpleFormController class and the problem is solved.

Matin Kh
  • 5,192
  • 6
  • 53
  • 77