Deep Dive into Data Validation with Vaadin – final part
Introduction This article is part of the series: 'Towards Vaadin Developer Certification,' which aims to explain the fundamentals of Vaadin while I study for this certification. The topics covered here are an integral part of the 'Vaadin Developer' Certification. The article was based on my notes. In the previous article, we discussed the first steps to validate data in Vaadin forms. Now, let's explore more about Vaadin's built-in validators and how to customize error messages. Vaadin Built-in Validators Vaadin already comes with several validators that can be used without custom configuration. Typically, these validators handle value ranges. Here are some: • BeanValidator • FloatRangeValidator • BigDecimalRangeValidator • IntegerRangeValidator • BigIntegerRangeValidator • LongRangeValidator • ByteRangeValidator • RangeValidator • DateRangeValidator • RegexpValidator • DateTimeRangeValidator • ShortRangeValidator • DoubleRangeValidator • StringLengthValidator • EmailValidator b) Built-in Converters Vaadin provides several built-in converters: • DateToLongConverter • StringToDateConverter • DateToSqlDateConverter • StringToDoubleConverter • LocalDateTimeToDateConverter • StringToFloatConverter • LocalDateToDateConverter • StringToIntegerConverter • StringToBigDecimalConverter • StringToLongConverter • StringToBigIntegerConverter • StringToUuidConverter • StringToBooleanConverter "writeBeanAsDraft" Method The Binder.writeBeanAsDraft(bean) method allows saving changes even when some fields do not pass validation. This is useful for saving incomplete forms: Conclusion Data validation in Vaadin forms is essential to ensure data integrity. With the various available techniques, we can create robust and efficient forms. Customizing the "asRequired" Method We can display error messages in different graphical components than the defaults. See how: Another more detailed way: Applying Validators to Binders We can apply validators directly to the Binder: *Binder with BeanValidation Support * We can associate Vaadin's validation system with Java's BeanValidation: Client-Side Validators We can perform validation directly in the browser, but this should not be used as the sole security measure: Conversions Fields and binders must have the same data type. When this does not occur, we use converters: a) Custom Converters We can create custom converters: • Disclaimer This content, although based on my studies and notes acquired during the Vaadin 24 certification process, does not intend to be exhaustive. For a deeper understanding of the topic, I recommend consulting the official Vaadin 24 documentation and the materials from the certification courses. Additionally, I would like to inform you that I used Artificial Intelligence tools to assist in the modeling and structuring of this article. However, the writing and the original content are exclusively authored by me, hence AI was utilized as a helpful tool, not as a replacement for my own authorship. Authors Paulo B. A. is an 'Oracle Certified Java Developer' and 'Spring Certified Professional' with a deep passion for Vaadin Flow. He crafts UIs with Vaadin and strives to make it the leading frontend framework for full-stack Java developers worldwide. He loves teaching, sharing knowledge, and creating content. While he enjoys learning theory through certifications, he always advocates for a practical approach. • Linkedin.com/in/pbalves • X.com/p_b_alves • Mastodon.social/@pbalves Staff Writer: Fábio A. P. is a technology enthusiast, self-taught writer, and scholar of society's relationship with technology. Passionate about sharing insights, he provides reliable perspectives on how technology shapes our lives. With clear and precise writing, Fábio simplifies complex topics, empowering readers to navigate the digital age with confidence. • Medium.com/@fabioape

Introduction
This article is part of the series: 'Towards Vaadin Developer Certification,' which aims to explain the fundamentals of Vaadin while I study for this certification. The topics covered here are an integral part of the 'Vaadin Developer' Certification. The article was based on my notes.
In the previous article, we discussed the first steps to validate data in Vaadin forms. Now, let's explore more about Vaadin's built-in validators and how to customize error messages.
Vaadin Built-in Validators
Vaadin already comes with several validators that can be used without custom configuration. Typically, these validators handle value ranges. Here are some:
• BeanValidator
• FloatRangeValidator
• BigDecimalRangeValidator
• IntegerRangeValidator
• BigIntegerRangeValidator
• LongRangeValidator
• ByteRangeValidator
• RangeValidator
• DateRangeValidator
• RegexpValidator
• DateTimeRangeValidator
• ShortRangeValidator
• DoubleRangeValidator
• StringLengthValidator
• EmailValidator
b) Built-in Converters
Vaadin provides several built-in converters:
• DateToLongConverter
• StringToDateConverter
• DateToSqlDateConverter
• StringToDoubleConverter
• LocalDateTimeToDateConverter
• StringToFloatConverter
• LocalDateToDateConverter
• StringToIntegerConverter
• StringToBigDecimalConverter
• StringToLongConverter
• StringToBigIntegerConverter
• StringToUuidConverter
• StringToBooleanConverter
"writeBeanAsDraft" Method
The Binder.writeBeanAsDraft(bean) method allows saving changes even when some fields do not pass validation. This is useful for saving incomplete forms:
Conclusion
Data validation in Vaadin forms is essential to ensure data integrity. With the various available techniques, we can create robust and efficient forms.
Customizing the "asRequired" Method
We can display error messages in different graphical components than the defaults. See how:
Another more detailed way:
Applying Validators to Binders
We can apply validators directly to the Binder:
*Binder with BeanValidation Support
*
We can associate Vaadin's validation system with Java's BeanValidation:
Client-Side Validators
We can perform validation directly in the browser, but this should not be used as the sole security measure:
Conversions
Fields and binders must have the same data type. When this does not occur, we use converters:
a) Custom Converters
We can create custom converters:
• Disclaimer
This content, although based on my studies and notes acquired during the Vaadin 24 certification process, does not intend to be exhaustive. For a deeper understanding of the topic, I recommend consulting the official Vaadin 24 documentation and the materials from the certification courses.
Additionally, I would like to inform you that I used Artificial Intelligence tools to assist in the modeling and structuring of this article. However, the writing and the original content are exclusively authored by me, hence AI was utilized as a helpful tool, not as a replacement for my own authorship.
Authors
Paulo B. A. is an 'Oracle Certified Java Developer' and 'Spring Certified Professional' with a deep passion for Vaadin Flow. He crafts UIs with Vaadin and strives to make it the leading frontend framework for full-stack Java developers worldwide. He loves teaching, sharing knowledge, and creating content. While he enjoys learning theory through certifications, he always advocates for a practical approach.
• Linkedin.com/in/pbalves
• X.com/p_b_alves
• Mastodon.social/@pbalves
Staff Writer: Fábio A. P. is a technology enthusiast, self-taught writer, and scholar of society's relationship with technology. Passionate about sharing insights, he provides reliable perspectives on how technology shapes our lives. With clear and precise writing, Fábio simplifies complex topics, empowering readers to navigate the digital age with confidence.
• Medium.com/@fabioape