WAS v8.5 > Develop applications > Develop applications that use Bean Validation APIUse bean validation in the product
The Java EE 6 specification includes the Bean Validation API that is a standard mechanism for validating JavaBeans in all layers of an application. Before the Bean Validation specification, JavaBeans were validated in each layer. To prevent the reimplementation of validations at each layer, developers bundled validations directly into their classes or copied validation code, which was often cluttered. Having one implementation that is common to all layers of the application simplifies the developers work and saves time. Bean validation is common to all layers of an application. Specifically, web applications have the following layers:
- Presentation
This layer represents how the user interacts with the application and might be built on a thin client or rich client.
- Business
This layer coordinates the application, processes commands, makes logical decisions and evaluations and performs calculations. It also moves and processes data between the two other layers. The EJB contains business logic in WebSphere Application Server.
- Data access
Your data is stored and retrieved from a database or file system at this layer. The business layer processes the data and sends it in usable form to the user interface. WAS supports several databases and methods of retrieving data. This layer also defines persistence.
For WAS, these layers are built and administered with several components in the product necessary for developing and deploying applications.
WAS v8.5 provides support for the Bean Validation API in the Java EE environment by providing a bean validation service in multiple Java EE technologies including Java Servlets, Enterprise JavaBeans, JPA 2.0, Java EE Connector API (JCA) 1.6 and Java ServerFaces (JSF) 2.0. Bean validation provides these technologies a way to maintain data integrity in an integrated and standard environment.
Enterprise application development involves multiple teams developing numerous applications and modules that are assembled and deployed in an application server environment. WAS v8.5 ensures that each application and module data is validated independently. Validation is performed using only the constraints defined for the application and module.
Subtopics
- Bean validation in RAR modules
WAS validates resource adapter archive (RAR) JavaBeans constraints in compliance with the Java Connector Architecture (JCA) version 1.6 specification.- Bean validation in JPA
Data validation is a common task that occurs in all layers of an application, including persistence. The JPA 2.0 provides support for the Bean Validation API so that data validation can be done at run time. This topic includes a usage scenario where bean validation is used in the JPA environment of a sample digital image gallery application.
- Data access resources:
Bean validation in RAR modules.WAS v8.5 validates resource adapter archive (RAR) EJB constraints in compliance with the JCA version 1.6 specification. Resource adapters can use the built-in bean validation constraint annotations or provide a bean validation XML configuration to specify the validation requirements of resource adapter configuration properties to the application server.
- Use bean validation in JPA
A new feature defined by the JPA 2.0 specification is the ability to seamlessly integrate with the Bean Validation API. With minimal effort, JPA 2.0 can be coupled with the validation provider for runtime data validation. By combining these two technologies, you get a standardized persistence solution with the added ability to perform standardized data validation.
- Using bean validation with JSF
JSF previously was able do bean validation, but now it provides built-in support of the Bean Validation specification.
- Using bean validation in web container
The web container provides an instance of ValidatorFactory and makes it available to JSF implementations by storing it in a servlet context attribute named javax.faces.validator.beanValidator.ValidatorFactory.
- Using bean validation with the embeddable container.
To use bean validation with the embeddable EJB container, the javax.validation classes must exist in the class path. That can be done in one of two ways:
- Include the JPA thin client located in the directory ${WAS_INSTALL_ROOT}\runtimes\com.ibm.ws.jpa.thinclient_8.0.0.jar in the class path. See the topic, Run an embeddable container, and the information about JPA, for more information.
- Include a third party bean validation provider JAR file in the class path of the embeddable EJB container run time.
Subtopics
- Bean validation in RAR modules
WAS validates resource adapter archive (RAR) JavaBeans constraints in compliance with the Java Connector Architecture (JCA) version 1.6 specification.- Bean validation in JPA
Data validation is a common task that occurs in all layers of an application, including persistence. The JPA 2.0 provides support for the Bean Validation API so that data validation can be done at run time. This topic includes a usage scenario where bean validation is used in the JPA environment of a sample digital image gallery application.
Related concepts:
Bean validation in RAR modules
Bean Validation
Bean validation in JPA
Migration of JPA applications and bean validation
Related
Run an embeddable container
Reference:
Bean validation built-in constraints
Related information:
Troubleshooting bean validation in RAR modules