Categories
Java Java Bean Validation

Dependencies

We are going to use Maven as build tool, we will discuss this in its context.

  1. As per JSR380 specification of set of APIs provided by following
<dependency>

    <groupId>javax.validation</groupId>

    <artifactId>validation-api</artifactId>

    <version>2.0.1.Final</version>

</dependency>

2. Hibernate validator is reference implementation for above specification.

<dependency>
	    <groupId>org.hibernate.validator</groupId>
	    <artifactId>hibernate-validator</artifactId>
	    <version>6.0.13.Final</version>
</dependency>

3. Expression language dependencies to be able to write expressions in validation messages.

<dependency>
	    <groupId>org.glassfish</groupId>
	    <artifactId>javax.el</artifactId>
	    <version>3.0.0</version>
</dependency

Categories
Java Java Bean Validation

Why java bean validation

Validation is often a basic requirement for any kind of application, be it user input over web page, desktop application, mobile application or be it schematic constraints at database level or compliance of XML with respect to XSD.

Validations are implemented in several ways, at various levels in technology stack from User interface to database schema. We may restrict that “User Name” field must not be empty on login form, we may restrict that “userName” column not be empty in database table, we may restrict that in XSD that input xml tag “UserName” shouldnt be empty. Apart from this several frameworks provide their own ready to use configurable mechanisms, struts provides Validator interceptors, Hibernate provide its own annnoation over bean properties corresponding to reflect database schema.

Java bean validation can be just another approach, for several reasons. Because It is easy, because POJO java beans are used in almost all frameworks so portability ensured, or because it reduces boilerplate codes which need not be written, or because it can be looked upon as alternative to avoid to database schema, XSD xml schema or User Interface, to give performance improvement choice.

Java bean validation needs Java8 or higher version. This specification is defined by JSR380. There can be several implementations for this specification.

Design a site like this with WordPress.com
Get started