We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
E.g.
public class BirthdayValidator extends BaseValidator<CharSequence> { private String pattern; public BirthdayValidator(String pattern) { this.pattern = pattern; } @Override public boolean validate(Annotation annotation, CharSequence input) { Calendar cal = Calendar.getInstance(); cal.set(Calendar.YEAR, cal.get(Calendar.YEAR) - 18); long acceptedBirthday = cal.getTimeInMillis(); long birthday; SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern); try { birthday = simpleDateFormat.parse(input.toString()).getTime(); } catch (ParseException e) { e.printStackTrace(); return false; } return birthday <= acceptedBirthday; } }
As I see from ValidatorFactory all validators are created with no-args constructor and this is pretty sad for such a nice library
ValidatorFactory
public static IValidator getValidator(Annotation annotation) throws IllegalAccessException, InstantiationException { if (annotation == null) { return null; } final Class<? extends IValidator> clazz = sValidators.get(annotation.annotationType()); IValidator validator = null; if (clazz != null) { validator = sCachedValidatorInstances.get(clazz); if (validator == null) { validator = clazz.newInstance(); sCachedValidatorInstances.put(clazz, validator); } } return validator; }
or even only
@ValidatorFor({Joined.class, Custom.class}) public class CustomValidator extends BaseValidator<Object> { @Override public boolean validate(Annotation annotation, Object input) { if (annotation instanceof Joined) { try { IValidator validator = ((Joined) annotation).validator().newInstance(); return validator.validate(annotation, input); } catch (InstantiationException e) { throw new FormsValidationException(e); } catch (IllegalAccessException e) { throw new FormsValidationException(e); } } else if (annotation instanceof Custom) { try { IValidator validator = ((Custom) annotation).value().newInstance(); return validator.validate(annotation, input); } catch (InstantiationException e) { throw new FormsValidationException(e); } catch (IllegalAccessException e) { throw new FormsValidationException(e); } } else { throw new FormsValidationException("unknown annotation " + annotation); } } }
@Custom(value = BirthdayValidator.class, args = {"MM/dd/yyyy hh:mm:ss aa"}, messageId = R.string.error_birthday_required)
The text was updated successfully, but these errors were encountered:
I created an extension instead of using the @Custom.
@Custom
Example https://gist.github.com/douglasjunior/5bf82f11f5f006a4b5b9
Works for me.
Sorry, something went wrong.
No branches or pull requests
Scope
E.g.
As I see from
ValidatorFactory
all validators are created with no-args constructor and this is pretty sad for such a nice libraryor even only
What is wanted
The text was updated successfully, but these errors were encountered: