• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

problem in form submit in spring

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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()));
}
 
Sheriff
Posts: 6450
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In your controller, you need to override doSubmitAction(), and not onSubmit(). Check out the API docs for the whole workflow.
 
Nuri Jain
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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);
}
}
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic