-
1. Re: Conditional hibernate validations?
asavitsky Sep 22, 2008 4:43 PM (in response to asiandub)Which version of validator are you using? The latest one (3.1.0) certainly doesn't fail email validation on empty or null fields:
public boolean isValid(Object value) {
if ( value == null ) return true;
if ( !( value instanceof String ) ) return false;
String string = (String) value;
if ( string.length() == 0 ) return true;
Matcher m = pattern.matcher( string );
return m.matches();
}
So you can annotate the extra email with @Email, and it will only fail if there's something in the field.Same story with the @Length validator - it won't fail on empty strings, either:
public boolean isValid(Object value) {
if ( value == null ) return true;
if ( !( value instanceof String ) ) return false;
String string = (String) value;
int length = string.length();
return length >= min && length <= max;
}Maybe it's the required="true" that's firing on your page, not HV?
-
2. Re: Conditional hibernate validations?
asavitsky Sep 22, 2008 4:47 PM (in response to asiandub)Mental note to myself -
code block
formatting is NOT the same asMonospace/Code
... sorry for the mess. -
3. Re: Conditional hibernate validations?
asiandub Sep 23, 2008 7:34 AM (in response to asiandub)thanks for answering,
what you are writing indicates that the problem is either the version of the validation framework or some parts of my business-logic.
I have to check version and source code of the validation.jar. so far i can only tell that I'm using the hibernate-annotations.jar which came with either jboss or seam. i'm currently not able to determine the version.
cheers,
jan -
4. Re: Conditional hibernate validations?
asavitsky Sep 23, 2008 7:30 PM (in response to asiandub)Inside the HV jar, META-INF/MANIFEST.MF should contain the version number
-
5. Re: Conditional hibernate validations?
joblini Sep 24, 2008 5:19 AM (in response to asiandub)Hello,
The listing for @Length (posted) doesn't contain the statement
if ( string.length() == 0 ) return true;
Regards,
Ingo