bean validation - Passing application context to JSR 303 ConstraintValidator -


some of jsr-3validation want context sensitive.

for example, web application has "year" context each request. when persisting new bean, want able constrain year property within year of current request context.

 @incurrentcontextyear  private localdate activationdate; 

the current year contained in request object want pass (in way) constraint validator. example:

public class incurrentcontextyearvalidator                    implements constraintvalidator<incurrentcontextyear, localdate>{      @override     public void initialize(incurrentcontextyear constraintannotation) {}      @override     public boolean isvalid(                           localdate value,                            constraintvalidatorcontext context,                           request request) {          return dateutil.isinrequestyear(value, request)     } } 

now thread-local storage, i'm wondering if there's better way.

i recognize getting outside domain of "bean validation" seems using annotations such things defensible approach. annotations allow me keep beans pojos, , service nice way document rules of properties. why should need have entirely separate mechanism same thing bean validation?


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -