views:

352

answers:

1

i have a login-validation.xml which define some basic field validation rules. however that's not enough for me. i need to do some more database lookup and i consider this as part of my validation logic. how can i do both xml validation and my database lookup in one go? i suppose i will write something like

public void validate() {
    1) struts2-validation.xml validation();
    2) myDatabaseLookup() and addFieldError() or addActionError();
}

my problem is, what is the api i can use for (1)?

or, how can i look at the code of this xml validation filter class? in fact i would also make the definitions in validation.xml available to javascript usage... i guess i would need to do some translation from xml to javascript logic, but first of all, how can i access the validation.xml api in java code?

A: 

Your best choice is to create a validator... Take a look here for some information -

Custom Validator

There are a few things to keep in mind... I don't know if the ObjectFactory will instantiate and inject your validator, so you might not have all the features of dependency injection. If your custom validator isn't injected, file a bug, I'll take a look at it.

After you create your validator and register it in your app, you can add it to the validation.xml file.

(side note, I know that I am pointing to the XWork docs, but Struts2 uses XWork internally for most of it's validation capabilities)

Wes W