The moose likes Spring and the fly likes problem in form submit  in spring Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Application Frameworks » Spring
Reply Bookmark "problem in form submit  in spring" Watch "problem in form submit  in spring" New topic
Author

problem in form submit in spring

Nuri Jain
Greenhorn

Joined: Jan 22, 2008
Posts: 10
I am bignner and I am trying to write simple spring example which takes name and surname input from jsp file and call the controller .
Its initially showing jsp page proper but after click on submit button i am not getting success page, as i dig out the code i come to know its not calling controller properly.
Please let me know where is the problem exactly.
1.<bean id="beanNameUrlMapping" class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping">
<property name="order"><value>0</value></property>
</bean>

2.
<bean name="/CreateContact.htm" class="com.CreateContactController">
<property name="formView"><value>CreateContact</value></property>
<property name="successView"> <value>ContactCreated</value> </property>
<property name="commandClass"><value>test.Contact</value></property>
<property name="commandName"><value>MyCommandName</value></property>
<property name="contactService"><ref local="contactService"/></property>
</bean>

4.public class CreateContactController extends SimpleFormController{

private ContactService contactService;

public void setContactService(ContactService contactService) {
this.contactService = contactService;
}
public CreateContactController() {
System.out.println("this is CreateContactController CreateContactController()");
setCommandClass(Contact.class);
}
public ModelAndView onSubmit(Object command) throws ServletException {
System.out.println("done");
Contact contact=(Contact) command;
ContactService.createContact(contact);
return new ModelAndView(new RedirectView(getSuccessView()));
}
Jason Menard
Sheriff

Joined: Nov 09, 2000
Posts: 6450
In your controller, you need to override doSubmitAction(), and not onSubmit(). Check out the API docs for the whole workflow.


Jason's Blog
Nuri Jain
Greenhorn

Joined: Jan 22, 2008
Posts: 10
Thanks for reply,I added doSubmitAction(Object command) method in my controller class but still the same problem i am not getting succesor page..its repetedly showling me only initial view page.As i observe its not reaching up to controller cause its not printing even Controller's construtor print statement.

I am giving here my complete controller class
Thanks in advance

1.public class CreateContactController extends SimpleFormController{

private ContactService contactService;

public void setContactService(ContactService contactService) {
this.contactService = contactService;
}
public CreateContactController() {
System.out.println("this is CreateContactController CreateContactController()");
setCommandClass(Contact.class);
}
//public ModelAndView onSubmit(Object command) throws ServletException {
// System.out.println("done");
//Contact contact=(Contact) command;
// ContactService.createContact(contact);
//return new ModelAndView(new RedirectView(getSuccessView()));
// }

public void doSubmitAction(Object command){
System.out.println("this is CreateContactController doSubmitAction");
Contact contact = (Contact)command;
ContactService.createContact(contact);
}
}
Rob Bradley
Greenhorn

Joined: Oct 10, 2003
Posts: 1
Nuri Jain wrote:Thanks for reply,I added doSubmitAction(Object command) method in my controller class but still the same problem i am not getting succesor page..its repetedly showling me only initial view page. As i observe its not reaching up to controller cause its not printing even Controller's construtor print statement.

I don't know if you still visit these forums Nuri but I was wondering if you ever managed to resolve this issue? I am having exactly the same problem right now, no matter what I do neither onSubmitAction nor doSubmitAction are ever getting called.
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4120

Check the workflow again in the API docs referenced above... Step 4:


If no errors occurred, the controller will call onSubmitAction...


One or more errors are being thrown before getting to onSubmitAction - probably form validation.


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Tanvi Narula
Greenhorn

Joined: Sep 30, 2008
Posts: 9
Hi,

I am also facing the same issue. Can anybody let me know how to check the errors that are being thrown. Because as such I am not using any form validations
jay anandan
Greenhorn

Joined: Apr 01, 2011
Posts: 2
check your form method whether it is "GET" or "POST". By default, only POST is treated as form submission. you can override the method "isFormSubmission" in your controller and decide when form submission should happen.
 
 
subject: problem in form submit in spring
 
Threads others viewed
how to tell MultiActionController Command Object is Of type com.dss.ems.model.User
Spring MVC question
Problem with getSuccessView
Spring MVC problem with AbstractWizardFormCOntroller
Neither BindingResult nor plain target object for bean name 'user' available as request attribute
MyEclipse, The Clear Choice