-
1. Re: Complex validation
supernovasoftware.com Feb 9, 2007 1:07 PM (in response to vladimir.kovalyuk)I have a lot of complex validations in my project.
I just put the logic in my action method and add the appropriate messages to a map as feed it to the function below.
If messages were added I redirect to the same page. This seems like an old fashioned what to do things, but I have not found a more JSF way to do this.
If anyone has a better solution, please let me know.
My validations are more complex than just inspecting the object to be persisted. I need to query the EntityManager to see if these changes are acceptable, not simply compare a few properties on an object.
I also do not like to have to put required="true" in order to validate null fields.
Is there any way around this?
Could Seam be made to override the default JSF implementation behavior in this case?public int addMessages(Map<String, String> m) { for(String key : m.keySet()) { if(key.startsWith("globalMessage")) { FacesMessages.instance().add(m.get(key)); } else { FacesMessages.instance().add(key, m.get(key)); } } return m.size(); }
-
2. Re: Complex validation
vladimir.kovalyuk Feb 9, 2007 2:12 PM (in response to vladimir.kovalyuk)It seems that simple validation (related to entity itself) is completely covered by Seam, except custom hibernate validators.
AFAIK hibernate validator is supposed to work without hibernate itself, for instance it should work with Kodo.
Complex validation (how entity correlates to the other entities, rules and policies) are not covered at all.
Since Seam already employs JBoss Rules for authorization I believe it's possible to perform complex validation using Rules as well. The only thing I'm concerned about is performance. -
3. Re: Complex validation
gavin.king Feb 9, 2007 4:16 PM (in response to vladimir.kovalyuk)"vladimir.kovalyuk" wrote:
It seems that simple validation (related to entity itself) is completely covered by Seam, except custom hibernate validators.
AFAIK hibernate validator is supposed to work without hibernate itself, for instance it should work with Kodo.
Complex validation (how entity correlates to the other entities, rules and policies) are not covered at all.
Since Seam already employs JBoss Rules for authorization I believe it's possible to perform complex validation using Rules as well. The only thing I'm concerned about is performance.
+1 -
4. Re: Complex validation
kukeltje Feb 11, 2007 12:38 PM (in response to vladimir.kovalyuk)Some less complex intra entity validations would be a nice first step. Things like : date A should be before date B. Element B is required if element A is not null. Has anyone written some 'generic' validators for these less complex validations
-
5. Re: Complex validation
pmuir Feb 11, 2007 12:43 PM (in response to vladimir.kovalyuk)[ur]http://jroller.com/page/jgilbert01?entry=extending_the_hibernate_validation_framework[/url]
This seems one approach - I would prefer to see EL used rather than JEXL and I'm not sure how it would tie into the JSF lifecycle (as the datamodel hasn't been updated in the process validations phase).
It strikes me that the big problem isn't actually *doing* complex validations but tying it into JSF. -
6. Re: Complex validation
wsollers Feb 11, 2007 3:05 PM (in response to vladimir.kovalyuk)Could you:
@ValidatorClass ( GreaterThanValidator.class ) @Retention ( RetentionPolicy.RUNTIME ) @Target ( { ElementType.METHOD } ) public @interface GreaterThan { String elExpr = null; String mesg = "#{someMessageKey}"; }
And then in the validator class get a reference to the Seam interpolator and invoke the el-binding cast it to Comparable and compare it to the annotated data element.
Could do the same for less than, either or, just a thought for the simpler things. To do entity exists checks I use a custom interceptor that has access to the entity manager to do the queries.
I am curious about this as well as I have lot's of these kind of things floating around and would really like to standardize them and will research it further.