javaxmlvalidationstruts2nullpointerexception

Is there a way to change the order of the validation: validate() vs validation.xml in Struts 2?


I have a validation.xml file to check if the fields of the form are empty and that kind of simple validation. I also have a validate() method (extended from ActionSupport) to check more complicated things. But when I send the form it checks the method before the XML file, so if the fields are empty a NullPointerException appears. At least that's what I think is happening.

So my question is, is there a way to change the order of the validation, so the XML is checked before the method?

EDIT:

I had the idea of checking if the String is not null in the validate() method, so I can avoid the problem, but I don't think that's the wisest thing to do.


Solution

  • The interceptor does check XML first, but IIRC doesn't stop validation if it find errors. I believe I have a patch for this, controlled with a flag.

    I've solved this before by checking for errors in the validate method and not proceeding if errors existed.