permaculture playing cards*
The moose likes Struts and the fly likes Struts2 Validation Framework mystery Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts2 Validation Framework mystery" Watch "Struts2 Validation Framework mystery" New topic
Author

Struts2 Validation Framework mystery

Jeff Beardsley
Greenhorn

Joined: May 27, 2014
Posts: 3
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'm using Struts version 2.3.16.3.

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.


  • Other Clues:
  • 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).
  • This page has lots of javascript, perhaps something that interferes with the invocation of server-side validation.


  • Questions:
  • 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.
  • Are there any known problems with javascript interfering with the functionality of the validation framework?


  • Many thanks if you've read this far
    Jeff Beardsley
    Greenhorn

    Joined: May 27, 2014
    Posts: 3
    Ok, I solved this one with a bit more experimentation:

    Important Note:
    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
    Bartender

    Joined: Oct 29, 2001
    Posts: 8843
        
        7

    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.


    "blabbing like a narcissistic fool with a superiority complex" ~ N.A.
    [How To Ask Questions On JavaRanch]
    Jeff Beardsley
    Greenhorn

    Joined: May 27, 2014
    Posts: 3
    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">
     
    It is sorta covered in the JavaRanch Style Guide.
     
    subject: Struts2 Validation Framework mystery
     
    Similar Threads
    Struts2:Action-validation.xml
    Struts2 validation
    Struts2 Field Validator in XML - regex issue
    Struts2 & validation [SOLVED]
    Form Validation using xml in struts2