• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Records are not being saved

 
Ranch Hand
Posts: 166
1
jQuery Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I am developing a web application based on struts2, hibernate and spring. The problem is that the details are not being saved in Database. Always the control reaches to prepare() method and it never goes to the register() method (as defined in struts.xml). Before i fill the details the registration form will have the screen with the validaions on the empty fields (which is not correct - i am not getting why these fields are appearing).

The code is as follows:

struts.xml



Customer.jsp


CustomerAction.java


CustomerAction-validation.xml



Whenever add button is pressed again the same input form with validations are appearing instead of saving in database and getting the registration successful screen.

thanks in advance

swapna
 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
every thing is happening because of below interceptors




when you implement preparable interface inorder to prepare method it is called before every method on that class executes. so instead of initializing and prepopulating your form inside prepare method you put it inside input method as you could see this method is exempted from validation by validation interceptor.
which is causing your first problem i.e first time when you are viewing that form it's being validated which we don't want.

next problem is happening because again calling the prepare method before it goes to the register method. now what prepare method does send time is that it reinitializes the form which we difinitely don't want because we want the form data. and after that when validation framework works on it it it sees that form fields are not having proper value that's why it redirects you to input page.

so no prepare method. if you really want a prepare method use an input method and along with that use one method called prepareInput this is a convention in struts2 . and in that case if prepare interceptor calls it before calling input method.

There could be other ways to handle such scenario but i know only this one.
 
Swapna latha
Ranch Hand
Posts: 166
1
jQuery Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks ayan. The main problem is that the control is not going from prepare to register method. Any idea about why this is happening
 
Ayan mallick
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's what i told for every method call prepare method would be called. now for fist time when you are displaying the form prepare method works fine. but after you fill up the form and submit it. It will go through interceptor stack. so again prepare method is executed which creates a new form instance and you loose all data filled up in form. then before your register method is called validation interceptor is called and it finds validation error.That's why it never reaches up to register method. it finds validation error and redirect you back to input page. remember what happens once all interceptors are executed successfully without any error then only method mapped to action is called.
 
How do they get the deer to cross at the signs? Or to read this tiny ad?
New web page for Paul's Rocket Mass Heaters movies
https://coderanch.com/t/785239/web-page-Paul-Rocket-Mass
reply
    Bookmark Topic Watch Topic
  • New Topic