aspose file tools*
The moose likes Struts and the fly likes When to get basic/essential data while handling a request 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 "When to get basic/essential data while handling a request" Watch "When to get basic/essential data while handling a request" New topic
Author

When to get basic/essential data while handling a request

Ari Kovak
Greenhorn

Joined: Nov 02, 2009
Posts: 3
This concerns an existing Struts1 app.

I have a form field used to identify a data object. When my form fails to validate its execute is never run which results in the data object never getting loaded. In many JSP's I want the data object's title and other information, which I can't access if my form validates with errors. Loading the data in the validate method feels wrong, but is it?

Currently the data is loaded in a parent "base" action class that is extended by many other actions. I was hoping there would be some kind of "init" method I could override (be it the Action or the ActionForm) that is always called regardless of validation.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

There isn't, although you could implement a custom request processor.

Personally, back in the days of Struts 1, I *never* used the automatic validation. I always had a base action class that had pre- and post-validation methods etc. and just called the validation manually--much more versatile, and it'd still use declarative validation by calling super. (Um, or the form's validate method, or something; I don't really remember.)
 
Consider Paul's rocket mass heater.
 
subject: When to get basic/essential data while handling a request
 
Similar Threads
When is validate called on a DynaValidatorForm?
how to clear form objects
Commons Validator
validate method is not being called
Struts 1.2.9 Validation.........