This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
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 Java 8 in Action this week in the Java 8 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!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Struts 1 - Validate method being called before page load
 
Similar Threads
Common JSP/Action displaying confirmation details
Property value not getting set in Action Form
Displaying error in multi page form.
Better way to update a form with struts ?
cewolf charts