• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

onSubmit() not getting called

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.





 
Ranch Hand
Posts: 672
4
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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..
 
nilu chan
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 672
4
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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


 
Ranch Hand
Posts: 206
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...



 
nilu chan
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 672
4
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic