This week's book giveaway is in the OCAJP forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide 1Z0-808 and have Jeanne Boyarsky & Scott Selikoff on-line! See this thread for details.
I maybe have a few misconceptions about Struts, please bear with me.
The Form --------
Ok, so I have an ActionForm where I override validate(). In validate(), all I do is create an ActionErrors instance and return it at the end of the method, adding ActionError instances as I need:
ActionError err1 = new ActionError(ActionErrors.GLOBAL_ERROR, "my.key");
my.key has been defined in MessageResources.properties in WEB-INF/classes - I have 'read this in' with <message-resources property="MessageResources" in my config file.
The Action ----------
In my Action class, all I do is forward to a page which has an html:errors/ tag on it.
The Problem -----------
No errors are rendered by the html:errors tag.
My questions are:
1. Why does this not work? 2. Should I be using saveErrors(req, errors) - does the validate="true" not save the errors in the request? If I should do this, do I do it in the validate(..) method of the form or the execute(..) method of the action? 3. I am using v1.2.4 of Struts. Do I still need to enable the Validator plug-in to enable the old mechanism to still work?
1. Could be any number of reasons. 2. No - it should save it for you. It isn't necessary. 3. You don't need the plugin for what you are doing.
I recommend using a debugger or inserting various System.out lines in your code to figure out what parts of your code are being entered. It might be that the validate method you wrote has the wrong parameters, causing the default validate method to run.