JSR-303 Bean Validation



Similar documents
Hibernate Validator. Olivier Devoisin Kevin Gallardo. Université Pierre et Marie Curie. 9 Decembre 2014

The Java EE 6 Platform. Alexis Moussine-Pouchkine GlassFish Team

An introduction to creating JSF applications in Rational Application Developer Version 8.0

This presentation will provide a brief introduction to Rational Application Developer V7.5.

Agilité des applications Java EE 6

How To Write A Validator In Java 1.1.1

OpenShift is FanPaaStic For Java EE. By Shekhar Gulati Promo Code JUDCON.IN

The Oracle Fusion Development Platform

Rapid Application Development. and Application Generation Tools. Walter Knesel

Oracle Application Development Framework Overview

Eclipse Web Tools Platform. Naci Dai (Eteration), WTP JST Lead

Java EE 6 development with Eclipse, Netbeans, IntelliJ and GlassFish. Ludovic Champenois Oracle Corporation

<Insert Picture Here> Java EE 7: the New Cloud Platform

<Insert Picture Here> Java EE 7: the New Cloud Platform

Spring 3.1 to 3.2 in a Nutshell. Sam Brannen Senior Software Consultant

<Insert Picture Here> Java EE 7. Linda DeMichiel Java EE Platform Lead

Server-side OSGi with Apache Sling. Felix Meschberger Day Management AG 124

The end. Carl Nettelblad

Java EE 7: Back-End Server Application Development

CrownPeak Java Web Hosting. Version 0.20

Building Web Services with Apache Axis2

RESIN APPLICATION SERVER JAVA EE 6 WEB PROFILE

Framework Adoption for Java Enterprise Application Development

EclipseLink. Solutions Guide for EclipseLink Release 2.5

JBoss Forums Guide. 1. Introduction

Why IBM WebSphere Application Server V8.0?

APPLICATION SECURITY ENHANCEMENTS IN JAVA EE 6

JBoss JEE5 with EJB3.0 on NonStop. JAVA SIG, San Jose

This presentation is for informational purposes only and may not be incorporated into a contract or agreement.

Mind The Gap! Setting Up A Code Structure Building Bridges

White Paper: 1) Architecture Objectives: The primary objective of this architecture is to meet the. 2) Architecture Explanation

Web Development with the Eclipse Platform

SAP NetWeaver Opens SAP ERP world. Amedeo Prodi SAP Italia

Supporting Multi-tenancy Applications with Java EE

Java and RDBMS. Married with issues. Database constraints

Case Studies of Running the Platform. NetBeans UML Servlet JSP GlassFish EJB

Java in Web 2.0. Alexis Roos Principal Field Technologist, CTO Office OEM SW Sales Sun Microsystems, Inc.

Java Servlet 3.0. Rajiv Mordani Spec Lead

APAC WebLogic Suite Workshop Oracle Parcel Service Overview. Jeffrey West Application Grid Product Management

Next-Generation ESB. Kevin Conner SOA Platform Architect, Red Hat Keith Babo JBoss ESB Project Lead, Red Hat. June 23rd, 2010

Eclipse 4 RCP application Development COURSE OUTLINE

How To Extend Content Broker Storage On Libs Libs (Libs) With Libs 4.5) And Libs 5.5

SAP Web Application Server 6.30: Learning Map for Development Consultants

Agile Best Practices and Patterns for Success on an Agile Software development project.

Developing modular Java applications

Understanding Business Process Management

Accelerated Java EE Open Source Development with Eclipse CON1905

Kohsuke Kawaguchi Sun Microsystems, Inc. hk2.dev.java.net, glassfish.dev.java.net. Session ID

Web Development in Java

WebSphere Business Monitor

Nicholas S. Williams. wrox. A Wiley Brand

How To Write A Web Framework In Java

Weaving Stored Procedures into Java at Zalando

Servlet 3.0. Alexis Moussine-Pouchkine. mercredi 13 avril 2011

applications. JBoss Enterprise Application Platform

ORM IN WEB PROGRAMMING. Course project report for 6WW Erik Wang

The Java EE 7 Platform and Support for the PaaS Model

<Insert Picture Here> Building a Complex Web Application Using ADF and Siebel

Complete Java Web Development

Spring Data JDBC Extensions Reference Documentation

Oracle JDeveloper 10g for Forms & PL/SQL

Customer Bank Account Management System Technical Specification Document

SAAS. Best practices for SAAS implementation using an Open Source Portal (JBoss)

3 Techniques for Database Scalability with Hibernate. Geert Bevin - SpringOne 2009

Converting Java EE Applications into OSGi Applications

Exploiting Runtime User Interfaces

Community Systems Management Open Source COSMOS Creation Review

Please do not SUPER SIZE ME enterprise integration using the Camunda Fox Plattform Ralf Sigmund OPITZ CONSULTING

T-Mobile Umsetzung und Einsatz

GlassFish v3. Building an ex tensible modular Java EE application server. Jerome Dochez and Ludovic Champenois Sun Microsystems, Inc.

JBoss Enterprise App. Platforms Roadmap. Rich Sharples Director of Product Management, Red Hat 4th April 2011

Enterprise Java Web Application Frameworks & Sample Stack Implementation

FACULTY INFORMATION SYSTEM BASED ON OPEN SOURCE TECHNOLOGIES

Quick Guide For Using Spring Roo and Spring Security In Rapid Web Application Development:

What s new in Spring 3.1?

Business Logic Integration Platform. D.Sottara, PhD OMG Technical Meeting Spring 2013, Reston, VA

Create a single 360 view of data Red Hat JBoss Data Virtualization consolidates master and transactional data

2012 LABVANTAGE Solutions, Inc. All Rights Reserved.

Applications. Oracle WebCenter 11 g Handbook: Build Rich, Customizable Enterprise 2.0. Oracle Press ORACLE. Philipp Weckerle.

<Insert Picture Here> Oracle Application Express 4.0

Administering batch environments

Japan Communication India Skill Development Center

Oracle WebLogic Server

Securing JAX-RS RESTful services. Miroslav Fuksa (software developer) Michal Gajdoš (software developer)

e ag u g an L g ter lvin v E ram Neal G g ro va P Ja

1. Introduction What is Slice? Background Why Slice? Purpose of this Document Intended Audience...

IBM SDK, Java Technology Edition Version 1. IBM JVM messages IBM

SOA REFERENCE ARCHITECTURE: WEB TIER

The Google Web Toolkit (GWT): Declarative Layout with UiBinder Basics

Leveraging the Eclipse TPTP* Agent Infrastructure

Grails 1.1. Web Application. Development. Reclaiming Productivity for Faster. Java Web Development. Jon Dickinson PUBLISHING J MUMBAI BIRMINGHAM

Adopt-a-JSR Program. Heather VanCura (JCP), Martijn Verburg (London Java Community), Arun Gupta (Oracle/Java EE)

Experiences with Open-Source BPM/SOA-based Stack using Java EE Rok Povše, Matjaž B. Jurič

Eclipse Summit Europe 2008

METADATA-DRIVEN QLIKVIEW APPLICATIONS AND POWERFUL DATA INTEGRATION WITH QLIKVIEW EXPRESSOR

HybriDroid: Analysis Framework for Android Hybrid Applications

Gantry Basics. Presented By: Jesse Hammil (Peanut Gallery: David Beuving)

Java Management Extensions (JMX) and IBM FileNet System Monitor

IBM Websphere Application Server as a Service

Patent Public Advisory Committee Meeting PE2E Status. David Landrith Patents Portfolio Manager July 14, 2011

Transcription:

JSR-303 Bean Validation Emmanuel Bernard JBoss, by Red Hat http://in.relation.to/bloggers/emmanuel Copyright 2007-2010 Emmanuel Bernard and Red Hat Inc.

Enable declarative validation in your applications Constrain Once, Validate

Emmanuel Bernard Hibernate Search in Action blog.emmanuelbernard.com twitter.com/emmanuelbernard http://lescastcodeurs.com

Constraints Constraint restriction on a bean, field or property not null, between 10 and 45, valid email... How is that useful give feedback to the user ensure that a service will behave correctly define service range of usability avoid adding crap to the database unless you like fixing the data manually

Constraints in Java Ecosystems Where should they be applied?

Constraints in the Java Ecosystem Java Client Side Presentation Layer Business Layer Data Access Layer Database How many models do you have? ONE

What is the solution? Uniform way to express a constraint everybody speaks the same language based on the domain model (JavaBeans ) Standard way to validate constraints one runtime engine same validation implementations shared Bridge for constraints out of Java land API to access the constraint repository

Declare a constraint public class Address { @NotNull @Size(max=30, message="longer than {max} characters") private String street1;... @NotNull @Valid private Country country; } public class Country { @NotNull @Size(max=30) private String name;... }

Groups Subset of constraints Partial validation screen of a wizard UI Constraints applied in a given use case Order constraint validations which depends on other validations when a constraint is resource/time intensive

interface Billable {} interface BuyInOneClick extends Billable, Default {} class User { @NotNull(groups=BuyInOneClick.class) PaymentMethod getdefaultcreditcard() {...} } @NotNull //Default group String getusername() {...} @GroupSequence(sequence={Default.class, Heavy.class}) interface Complete {}

Create your own constraint Annotations with expressive names List of ConstraintValidators Constraint composition

@Constraint(validatedBy={ SizeValidatorForCollections.class), SizeValidatorForString.class } ) public @interface Size { String message() default "{constraint.size}"; Class<?>[] groups() default {}; Class<? extends Payload> payload() default {}; } //custom attributes int min() default 0; int max() default Integer.MAX_VALUE;

public class SizeValidatorForString implements ConstraintValidator<Size, String> { public void initialize(size annotation) {} } public boolean isvalid(string value, ConstraintValidatorContext context) {}

Composition Reuse constraints Expose meta-informations @NotNull @Size(min=5, max=5) @Constraint(validatedBy=FrenchZipCodeValidator.class) public @interface FrenchZipCode { String message() default "{constraint.frenchzipcode}"; Class<?>[] groups() default {}; Class<? extends Payload>[] payload() default {}; }

Message Can be externalized Internationalization Interpolate constraint parameters must be shorter than {min} Custom MessageInterpolator strategy Useful for application frameworks Contextual data Locale

How to use Bean Validation Standalone JPA 2.0 JSF 2.0 EE 6

Bootstrap API extensible support multiple implementations type-safe can override some attributes contextually XML configuration optional META-INF/validation.xml

ValidatorFactory vf = Validation.buildDefaultValidatorFactory(); ValidatorFactory vf = Validation.byDefaultProvider().configure().messageInterpolator( containermi ).traversableresolver( jpatr ).constraintvalidatorfactory( webbeansdi ).buildvalidatorfactory(); ValidatorFactory vf = Validation.byProvider(HibernateValidationProvider.class).configure().messageInterpolator( containermi ).failfast().enablelegacyconstraints().buildvalidatorfactory();

Manual validation Get a Validator from a ValidatorFactory Set<ConstraintViolation<User>> errors = validator.validate(user); Set<ConstraintViolation<User>> errors = validator.validate(user, BuyInOneClick.class); ConstraintViolation error message / message template invalid value

Accessing the metadata DDL generation, tools, JavaScript generators Metadata API BeanDescriptor - validator.getconstraintsforclass(user.class) PropertyDescriptor - beandescr.getconstrainedproperties() ConstraintDescriptor - descr.getconstraintdescriptors() - constrdescr.getcomposingconstraints() Shines with: composition built-in annotations

JSF 2 integration Zero conf Validate input components find property via Expression Language call Bean Validation on input value return localized error messages use JSF user Locale custom MessageInterpolator

Java Persistence 2 On entity change validation can select the groups validated Make use of a custom TraversableResolver do not traverse associations

Java EE 6 Validator as an injectable resource @Resource Validator validator; //or @Resource ValidatorFactory vf; Or in CDI (Java Context and Dependency Injection) @Inject Validator validator; //or @Inject ValidatorFactory vf;

Disclaimer I am NOT a designer

Disclaimer I am REALLY NOT a designer

Demo Validating in Java EE 6

Bean Validation Status. It s done.

Hibernate Validator 4 Released too. 4.0.2 What are you waiting for? Road Map backward compatible with legacy Hibernate Validator usage some cool ideas out of the spec scope License ASL 2.0

Questions? Or not? JCP.org search 303 http://in.relation.to bean validation tag Hibernate Validator http://validator.hibernate.org http://forum.hibernate.org/viewforum.php?f=26