This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Struts2 is new to me, and I don't know all the ins and outs -- I am hoping someone reads this and has a useful pointer for debugging this issue, as I've banged my head on it for several days with no progress.
I have a problem wherein the validation-framework fails to call my custom validator: "storename".
Here's what we know:
The Validator Works on another page in the application. This other page successfully uses the validator in exactly the same manner as my new page. In both pages the validator is referenced in a validation-framework xml file as follows (these files differ only in the name of the field to be validated)
The Validator Framework XML is being loaded. Notice that the sample above has two field-validators on the storeName field. The first one, "requiredstring" is called in all cases (as are most of the other field validators on the page, the single exception being "storename").
It's not an accessor problem. Notice again that the example has two field-validators on the storeName field, and the first one is always called.
Only client-side validators are working. I don't know if this is much of a clue, but: My validator requires the database, therefore is a server-side validator. All the other validators can be checked client-side, and they do seem to be checked without hitting the server at all (as far as I can tell).
Is there something special I need to do to support server-side validation? Disable client-side validation perhaps? I've found no discussion along these lines.
Many thanks if you've read this far
Joined: May 27, 2014
Ok, I solved this one with a bit more experimentation:
Using the <submit action="ActionToTake"> will not invoke server-side validation framework code. This only works with the method form of the element: <submit method="methodToCall">. I was expecting the two to be interchangeable, because the same method would get called in either case, however, no.
Joe Ess wrote:Thanks for checking back in. This probably has something to do with Struts following the JavaBeans Specification where method and property names are assumed to start with lower case variables.
In the case of Actions, however ... the action is neither a method, nor a property, but rather an XML configuration element. This element itself uses the usual JavaBeans convention as found in it's attribute: method="methodToCall". The naming scheme for the action itself however, starts with uppercase, as in <action name="ActionToTake" class="com.example.MysteriousAction" method="methodToCall">