Check out the Struts source code <http://jakarta.apache.org/site/cvsindex.html> and look at the ValidatorPlugIn or the TilesPlugIn, or just check out the Java Doc for the class (note this is Struts 1.1):If you want your actions to be able to deal with multiple forms for some reason, you could write a Struts PlugIn that puts itself into the ServletContext at initialization time, and then is available to all of your actions to validate the ActionForms.Intersting. Can you give me a link? Or an example? Sorry if I seem obtuse.
<http://jakarta.apache.org/struts/api/org/apache/struts/action/PlugIn.html>
Basically, PlugIn is a simple interface (two methods, init and destroy); you tell Struts about your PlugIn class in the struts-config.xml file, and Struts creates an instance of that class at initialization time and calls init(ActionServlet servlet, ApplicationConfig config). When I've used it, I have my PlugIn implementation call servlet.getServletContext().setAttribute("some.key",this); Then all my actions have access to the servlet context and can request the same class.
Your plugin could have a method like "validate(ActionForm)", and then your actions could just find the plugin and pass the form to it, and you could hide all the complexity of how the forms get validated in the plugin.
Understandable. Check out Commons Digester if you want to see just how easy it can be to pull XML into your java environment without screwing around with DOM or SAX...No. But I want them to be configurable at runtime. I suppose I could do that in an XML file, but databases are more natural for me personally.Is there a strong reason to have the validation rules in a database instead of in an XML file?
commons-validator is a system for validating beans based on an XML configuration file. It was originally written for Struts, and then was broken down into a non-struts validating core plus some pieces to allow you to use it more easily in Struts.Have you checked out the Validator system?No. What is that?
I haven't used it myself yet, because I usually don't have supremely complicated form validation and I find it easier to do it in my actions.
The JavaDoc is here <http://jakarta.apache.org/struts/api/org/apache/struts/validator/package-summary.html#package_description> It may be that some more avid users could point you to more documentation...
Joe
PS Here's an example of how I initialize my latest plugin. This method is called from the main "init()" method. MailController is the class which my plugin manages and puts into context. Its "parse()" method essentially passes the XML file identified by "config" over to commons Digester. This basic mechanism would work for just about any kind of class that you want to have initialized at application startup and available to all of your Actions.
private void initializeController(ActionServlet servlet) throws ServletException {
URL configURL = null;
try {
configURL = servlet.getServletContext().getResource(this.config);
}
catch (MalformedURLException ex) { }
if (configURL == null)
{
configURL = Thread.currentThread().getContextClassLoader().getResource(this.config);
}
if (configURL == null) throw new ServletException("No resource found for " + this.config);
try {
this.controller = MailController.parse(configURL.openStream());
}
catch (IOException ex) {
throw new ServletException("error reading " + configURL,ex);
}catch (EmailException ex) {
throw new ServletException("error parsing " + configURL,ex);
}
servlet.getServletContext().setAttribute(this.key, this.controller);
}
--
--
* Joe Germuska { [EMAIL PROTECTED] }
"It's pitiful, sometimes, if they've got it bad. Their eyes get glazed, they go white, their hands tremble.... As I watch them I often feel that a dope peddler is a gentleman compared with the man who sells records."
--Sam Goody, 1956
--
To unsubscribe, e-mail: <mailto:struts-user-unsubscribe@;jakarta.apache.org>
For additional commands, e-mail: <mailto:struts-user-help@;jakarta.apache.org>