-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
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
Spring Boot Form Validation with JTE #284
Comments
No, this isn't implemented in the spring-boot-starter as far as I'm aware of. I think you would need to find a way to pass the That being said, jte has an But the unit tests here show what's possible: You can basically automatically bind controller values to HTML elements, show field errors, etc. At least we could do all of that in Stipes :-) |
Thanks for pointing out the You are using stripes at work and with jte? |
Yes, but it is rather for historic reasons and we maintain our own fork of it by now. But it is a very lightweight, easy to understand and highly customizable framework. Good luck with the validation! |
I saw this issue and wanted to give some insight into how I've solved this. I didn't want to add the BindingResult to the Model each time because it is repetitive and the view you're returning of the form would likely used templates for the form inputs which meant you'd have to pass the BindingResult along with each of those templates. Spring has the concept of an
This seems to me exactly what I want, to automatically add the BindingResult BEFORE the view is rendered. So I setup a In the
The ThreadLocal is necessary to couple the right BindingResult to the in-flight request and can then be accessed when rendering the template. The code to init the JteContext in the JteContextInterceptor:
I also init some other things as you can see in the Having done this, I now simply do a static import of my JteContext in my templates and can then easily interact with the BindingResult without having to pass it around from controller to view and to its children templates, an example would look like this:
I've left out some bits of code here and there as I've taken this from a larger project so apologies if there are any inconsistencies. Happy to hear your thouhts too @casid about the implementation approach. |
Hi Andreas, first of all thanks for the awesome template engine.
I would like to use Spring Boot Validation, like with Thymleaf, e.g. https://stackabuse.com/spring-boot-thymeleaf-form-data-validation-with-bean-validator/
Is it possible to access the BindingsResult, like in the Thymleaf example with
${#fields.hasErrors('age')}
?I am not sure, if this is possible.
The text was updated successfully, but these errors were encountered: