In Xwork, Can't -validation.xml be placed somewhere else than in the same package as the corresponding Action class

148 Views Asked by At

I'm working on service side POJO validation using xwork. I am having an action, say ValidationAction.java, and I have a corresponding xml file named ValidationAction-validation.xml, which has validation rules on fields.

As per the specification and the documentation I could find, I understand that this xml file should be kept in the same package as the ValidationAction.java file. However, since I do have many java files to go through validation, and hence many corresponding xml files, I don't want to put them together in the same package.

I want to have a different folder/package for the xml files.

Is there any way out for this?

Thanks and regards.

1

There are 1 best solutions below

0
On

You are putting them in the same pacage because that's how xwork validators work. What you can do, if you don't want to do all this, is implement the Validatable interface: define a custom validate() method on your action which will be called before the Action will be executed.

Example:

public void validate() {
    if (todoManager.getTodo(id) == null) {
        String error = getText("todo.err.notFound");
        addActionError(error);
    }
}