*
The moose likes Spring and the fly likes onSubmit() not getting called Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "onSubmit() not getting called" Watch "onSubmit() not getting called" New topic
Author

onSubmit() not getting called

nilu chan
Greenhorn

Joined: Aug 31, 2010
Posts: 17
I am trying to submit a form and the onSubmit() method is not getting called and values of the form not getting bound the model bean. Not sure as to where I am messing it up. I am using Spring 2.0

I have a JSP page that captures some user input, a simple bean that binds these user input values through the controller (extends SimpleFormController) and then displays all the values captured in the success page. This works without any problems and the toString() method of the bean displays the user input values without any issues. However, the success page itself is a another jsp form that again captures user information, has a bean attached to it and a controller (extends SimpleFormController) that does the processing. However the onSubmit() method of this second controller never gets called. Not sure why.

Files:
studentForm.jsp --Displays user input studentName and age
StudentBean.java --Stores user input studentName and age successfully
StudentFormController.java --Once the user submits the form, takes the user to the success page
studentSuccess.jsp --Displays studentName and age on top of the page using by jsp el ${studentBean} and displays another user input DOB and Sex at the bottom of the page
StudentBean2.java --Stores user input DOB and Sex
StudentFormController2.java --Once the user submits the form, takes the user to the second success page (onSubmit() method NEVER GETS CALLED)
finalSuccess.jsp --Displays DOB and Sex using jsp el {studentBean2}

Am I not supposed to extend SimpleFormController ? Please guide.





Prasad Krishnegowda
Ranch Hand

Joined: Apr 25, 2010
Posts: 507

You can show us your code here.. For this requirement, AbstractWizardFormController is the best bet..
P:S: Still using SimpleFormController?, they are deprecated from Spring 3.x onwards and will be removed sooner.. I would recommend @Controller way of controllers..


Regards, Prasad
SCJP 5 (93%)
nilu chan
Greenhorn

Joined: Aug 31, 2010
Posts: 17
Prasad Krishnegowda wrote:You can show us your code here.. For this requirement, AbstractWizardFormController is the best bet..
P:S: Still using SimpleFormController?, they are deprecated from Spring 3.x onwards and will be removed sooner.. I would recommend @Controller way of controllers..


Yes. I agree AbstractWizardController is best bet for situations when we have wizard-like forms. But this situation does not apply to my code base as the problem that I presented to you is a simplified version of my sample Shopping Cart application (under development).

Here's my code:
dispatcher-serlvet.xml


studentForm.jsp


StudentBean.java


StudentFormController.java


studentSuccess.jsp



StudentFormController2.java


StudentBean2.java


finalSuccess.jsp
Prasad Krishnegowda
Ranch Hand

Joined: Apr 25, 2010
Posts: 507

You go to studentSuccess.jsp, and there you enter the other two fields, and press submit (no action in form tag), You expect form to be submitted to spring SimpleFormController, how spring will come to know this, you have come to this page, by requesting this page only, not through the .htm. using RedirectView in first controller, should solve this problem..

P:S: Still i am not convinced, why AbstractWizardFromController, doesn't suit your requirement here. Can you please explain in detail.
nilu chan
Greenhorn

Joined: Aug 31, 2010
Posts: 17
As per your suggestion this is what I tried.
1) Modified StudentFormController.java by replacing getSuccessView() with new RedirectView()
2) Added a new url mapping in dispatcher-servlet.xml


StudentFormController.java


dispatcher-servlet.xml


This magically WORKED, however I cannot see all the values of the first user input in the studentSuccess.jsp as I am using ${studentBean}. Looks like because of Redirect the values stored in the StudentBean are lost. Any suggestions for this? Code snippet shown below.

studentSuccess.jsp


Tommy Delson
Ranch Hand

Joined: Apr 13, 2011
Posts: 206
With a quick look on your code I can tell that your "studentForm.jsp" is not probably configured plus if you're using simpleFormController you have to map, wire, and inject reference everything in xxx-servlet.xml and in your Controller you're passing the Dependency Inject in.

I don't see any Command name you set in "studentForm.jsp" and what's your Command object?

For example,



You need to have a Command, Domain, Service, and Controller objects together for the application and use of simpleFormController.

All I see in your codes are jsp pages, domain and Controller, and the rest is missing. I assumed that you don't use any DAO.

To capture data on the jsp you need to set the session in your controller, and to retrieve it you get from the session.

Your codes won't work. There are a lot of work that need to be done even after you fix everything your codes hard to maintain and out dated.

I recommend utilize Spring Annotation Controller, it's simple and straight forward.

You can refer to Spring reference document and all resources on website to get started.

Hope it help...




OCPJP6-05-11
"Your life is in your hands, to make of it what you choose."
nilu chan
Greenhorn

Joined: Aug 31, 2010
Posts: 17
I agree Tommy that this can be done more easily using Spring 3.0 but what if somebody wants to do the same stuff using Spring 2.x. Moreover, if the binding of the command object, the form view and success view is done in the Controller itself then do we still need to specify it in the xxx-servlet.xml file again and yes you are right I am not using any DAO at this point. I am just trying to get things working first. My question is more of like "How to resolve this kind of issue?" rather than "What's the best way to do it?". Moreover my code binds user input to the command object without using spring form tag library. Is it necessary to use spring form tag library?

I am just trying to store user input's in a bean and print them out on the next page. Hope this clarifies on what exactly I am trying to achieve.
Prasad Krishnegowda
Ranch Hand

Joined: Apr 25, 2010
Posts: 507

Tom already answered your question.. here is what he said.
To capture data on the jsp you need to set the session in your controller, and to retrieve it you get from the session.
nilu chan
Greenhorn

Joined: Aug 31, 2010
Posts: 17
Prasad Krishnegowda wrote:Tom already answered your question.. here is what he said.
To capture data on the jsp you need to set the session in your controller, and to retrieve it you get from the session.


Got it. Thanks for the guidance.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: onSubmit() not getting called
 
Similar Threads
How do I create a basic confirmation page with dynamic content?
Spring MVC onSubmit not called
Populate Backing Bean Exception Handling
Property binding error
MVC Model 2 vs Spring SimpleFormController (Why formBackingObject() gets called twice?)