I'm looking for additional information on techniques for populating select lists from a database when using the
Struts Validator. Note that I am somewhat new to Struts, and am currently using Struts 1.2.9.
As I would assume is common in the industry, I need to load select options from a database to use in my form. In many examples, doing this type of thing is often shown in an action method, where the necessary options are loaded and put into the request before forwarding to the
JSP page.
The problem arises when you introduce Struts Validation. If a validation fails, the action's execute method never gets called, and thus can't be used to load data into the request for use by the form.
I found one page online that addresses this issue:
http://www.learntechnology.net/content/struts/validate_manually.jsp This page was a welcomed find, but I have to say that I didn't like any of the proposed solutions. To those that have dealt with this problem, what kind of options did you consider, and what resources or web sites did you find that talked about it?
Further Thoughts:
The fact that the execute method never gets called when there is a validation failure I think makes sense, which makes me question whether the action method is really where setting up the next page should be taking place. Why should the current page's action have to do anything more than accomplish the requested task and decide what page to go to next, without having to do setup for that next page? Instead of going from an Action method to a JSP page, why isn't there a step inbetween to perform any necessary setup for the JSP page? Not only would this potentially fix this validation issue (validation could then skip the action execution but the setup method for the JSP would still be called), it would also potentially reduce code duplication when multiple different actions return to the same JSP page (though this can also be mitigated by having a seperate setup method for such JSP pages within something like a DispatchAction class).
Thanks,
Scott