File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Struts 1 - Validate method being called before page load Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts 1 - Validate method being called before page load" Watch "Struts 1 - Validate method being called before page load" New topic
Author

Struts 1 - Validate method being called before page load

bryan nelson
Ranch Hand

Joined: Jun 16, 2003
Posts: 95
Hello there,

My validate method seems to be being called before the page ever loads...meaning before the form is ever populated. I only need it to be called after the form is submitted. I believe there is some way to fix this but I have searched and cannot find it.

Any ideas?

Thank you!


"...and the Truth will set you free."
bryan nelson
Ranch Hand

Joined: Jun 16, 2003
Posts: 95
Perhaps I should clarify that I am using DispatchAction.
bryan nelson
Ranch Hand

Joined: Jun 16, 2003
Posts: 95
Apparently DispatchAction and the validate() method don't always play nicely together. You can do a search to find out the details of why this is...but here is a solution:

If you place the following check in your validate method you will be able to safely skip the first call to validate (on the initial form load) while still hitting the second call on form submission as intended.



Basically you're just checking to see whether or not your DispatchAction parameter has a value set to it yet. If it doesn't, it's the initial load. If it does, then it is actually the form submission.

Hope this helps someone!
 
jQuery in Action, 2nd edition
 
subject: Struts 1 - Validate method being called before page load