I realize that this is the "Bean" validation framework, but I was wondering if there is any way to validate a value without necessarily tying it to a bean? We have a Swing-based UI which is not always bound to a bean. I would like to be able to do something like this:
String idOrURI = "protein.accession.swissprot"; ... public Set<ConstraintViolation> validate(String idOrURI, Object value){ Validator validator = ValidatorFactory.getValidator(idOrURI); // get validator using an ID or an ontology URI return validator.validate(value); }
To validate the value found in a Swing component I would assign a name (in the form of an ID or URI) to a component and then inject validators, and listeners to the component, so that it would validate whenever the user changes the value. By separating the validation criteria from either the bean used to store the value, or the UI component, I could use the same set of validation constraints to the same field regardless of where it occurs within the app.
I imagine that the same type of approach would also be useful for validating values from web UI components.
Any advice would be appreciated.
Regards,
Mark
|