Can I pass an object to a model before it's validate method is called? #12828
Unanswered
mjackson-mim
asked this question in
Q&A
Replies: 1 comment
-
Maybe it would be better and more conformant to the usual Jakarta validation if you added a custom constraint instead of injecting the validation in the model.
ValidUrl can be your own constraint annotation, that uses Then whenever your model is validated, a UrlValidator will be automatically injected and will try to validate the field without you polluting the model. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'm using Play! 3.0.2 with Java 21 on the back end, and I have a model that implements Constraints.Validatable<T>, that I'm binding to a form using Form<T>.bindFromRequest(request). I need to use a service class in
validate()
's body, but I want to pass in the implementation of the service class at runtime. Is there a way to do one of the following:An example:
Things I've tried / work-arounds I know about
Form.get()
, with no luck.Guice.createInjector().getInstance(UrlValidator.class)
, but that is bad practice.Any help is greatly appreciated!
Beta Was this translation helpful? Give feedback.
All reactions