SlideShare a Scribd company logo
1 of 45
Download to read offline
(C) CASAREAL, Inc. All rights reserved.
#glassfish_jp
1
(C) CASAREAL, Inc. All rights reserved.
#glassfish_jp
▸
▸
▸
▸
2
(C) CASAREAL, Inc. All rights reserved.
#glassfish_jp
▸
▸
▸ 

▸
▸
3
(C) CASAREAL, Inc. All rights reserved.
#glassfish_jp
▸
4
(C) CASAREAL, Inc. All rights reserved.
#glassfish_jp
▸
▸
▸
▸
▸ 💖
5
(C) CASAREAL, Inc. All rights reserved.
#glassfish_jp
6
(C) CASAREAL, Inc. All rights reserved.
#glassfish_jp
7
(C) CASAREAL, Inc. All rights reserved.
#glassfish_jp
▸
▸
▸
8
(C) CASAREAL, Inc. All rights reserved.
#glassfish_jp
▸
▸ 

▸
9
(C) CASAREAL, Inc. All rights reserved.
#glassfish_jp
10
public class HelloDto {
@NotBlank(message = "{hello.notblank}")
private String message;
// getter/setter
}
@Path("/hello")
public class HelloResource {
@POST
public Response post(@Valid HelloDto helloDto) {
//
}
}


(C) CASAREAL, Inc. All rights reserved.
#glassfish_jp
▸
11
hello.notblank	=	
▸
▸
hello.notblank = Message is required
hello.notblank =
ValidationMessages_ja.properties
ValidationMessages_en.properties
(C) CASAREAL, Inc. All rights reserved.
#glassfish_jp
12
$	curl	-v	-X	POST		
		-H	"Content-Type:	application/json”		
		-d	‘{"message":""}'		
		http://localhost:8080/api/hello			
>	POST	/api/hello	HTTP/1.1	
>	…	
>	
<	HTTP/1.1	400	Bad	Request	
<	…	
<	
{	
		"errorType":" ",	
		"messages":[" "]	
}
※JSON ExceptionMapper
(C) CASAREAL, Inc. All rights reserved.
#glassfish_jp
▸
13
Bean Validation 

(C) CASAREAL, Inc. All rights reserved.
#glassfish_jp
14
(C) CASAREAL, Inc. All rights reserved.
#glassfish_jp
▸ 👏
▸
15
(C) CASAREAL, Inc. All rights reserved.
#glassfish_jp
▸
▸
▸
▸
▸
16
(C) CASAREAL, Inc. All rights reserved.
#glassfish_jp
17
(C) CASAREAL, Inc. All rights reserved.
#glassfish_jp
▸ @NotNull	
▸ @Null	
▸ @NotEmpty	
▸ @NotBlank	
▸ @AssertTrue	
▸ @AssertFalse	
▸ @Size	
▸ @Pattern
18
▸ @Email	
▸ @Digits	
▸ @DecimalMax	
▸ @DecimalMin	
▸ @Max	
▸ @Min	
▸ @Positive	
▸ @PositiveOrZero
▸ @Negative	
▸ @NegativeOrZero	
▸ @Past	
▸ @PastOrPresent	
▸ @Future	
▸ @FutureOrPresent
※
(C) CASAREAL, Inc. All rights reserved.
#glassfish_jp
19
@NotBlank CharSequence
null 	
❌
@NotEmpty


null 0 ❌
@Email CharSequence
❌
@Positive ❌
@PositiveOrZero 0 ❌
(C) CASAREAL, Inc. All rights reserved.
#glassfish_jp
20
@Negative ❌
@NegativeOrZero 0 ❌
@PastOrPresent
Date Calendar 	
java.time.*
	
❌
@FutureOrPresent
Date Calendar 	
java.time.*
	
❌
(C) CASAREAL, Inc. All rights reserved.
#glassfish_jp
▸ @NotBlank @NotEmpty @Email 👏
▸ 

▸ 👏
▸ @Past @PastOrPresent @Future
@FutureOrPresent
21
(C) CASAREAL, Inc. All rights reserved.
#glassfish_jp
▸ @Past 

👏
▸ @Max/@Positive 

javax.money.MonetaryAmount
👏
▸ 

22
(C) CASAREAL, Inc. All rights reserved.
#glassfish_jp
23
(C) CASAREAL, Inc. All rights reserved.
#glassfish_jp
24
public class Sample {
private Optional<@Size(min = 3) String> optionalString;
private List<@NotNull String> list = new ArrayList<>();
		//	omitted	
}
▸ 👏
▸
※JSR Container element constraints
(C) CASAREAL, Inc. All rights reserved.
#glassfish_jp
▸ OptionalXxx java.util.OptionalInt 

XxxProperty IntegerProperty 

👏
25
public class Sample {
@Max(10)
private OptionalInt optionalInt;
		//	omitted	
}
(C) CASAREAL, Inc. All rights reserved.
#glassfish_jp
26
@Test
public void test() {
Sample sample = new Sample();
sample.addToOptionalString(“aa"); // 3
sample.addToList(null); // not null
sample.addToOptionalInt(20); // 10
//
Set<ConstraintViolation<Sample>> violations =
validator.validate(sample);
//
assertEquals(3, violations.size());
}
(C) CASAREAL, Inc. All rights reserved.
#glassfish_jp
27
@Test
public void test2() {
Sample sample = new Sample();
sample.addToList(null); // not null 1
sample.addToList(null); // not null 2
//
Set<ConstraintViolation<Sample>> violations =
validator.validate(sample);
//
assertEquals(2, violations.size());
}
▸
(C) CASAREAL, Inc. All rights reserved.
#glassfish_jp
28
(C) CASAREAL, Inc. All rights reserved.
#glassfish_jp
@Max(value = 100, groups = Group1.class)
@Max(value = 200, groups = Group2.class)
int	someValue;
▸
▸ @Xxx.List 👏
29
@Max.List({
@Max(value = 100, groups = Group1.class),
@Max(value = 200, groups = Group2.class)
})
int	someValue;
(C) CASAREAL, Inc. All rights reserved.
#glassfish_jp
▸
ParameterNameProvider
👏
▸ -parameters
30
(C) CASAREAL, Inc. All rights reserved.
#glassfish_jp
▸ ConstraintValidator
initialize()
▸
31
(C) CASAREAL, Inc. All rights reserved.
#glassfish_jp
32
(C) CASAREAL, Inc. All rights reserved.
#glassfish_jp
▸
👏
33
(C) CASAREAL, Inc. All rights reserved.
#glassfish_jp
34
<web-app …>
<context-param>
<param-name>
javax.faces.validator.ENABLE_VALIDATE_WHOLE_BEAN
</param-name>
<param-value>true</param-value>
</context-param>
<!-- omitted -->
</web-app>




(C) CASAREAL, Inc. All rights reserved.
#glassfish_jp
35
public class EqualsValidator
implements ConstraintValidator<Equals, Object> {
@Override
public boolean isValid(Object obj,
ConstraintValidatorContext context) {
// 2
// true
}
@Constraint(validatedBy = EqualsValidator.class)
public @interface Equals {
String property1(); // 1
String property2(); // 2
(C) CASAREAL, Inc. All rights reserved.
#glassfish_jp
36
@Named
@ViewScoped
@Equals(property1 = "email1", property2 = "email2",
message = “…”)
public class CompareBean implements Serializable {
@NotBlank(message = “…”)
@Size(min = 3, message = “…”)
private String email1;
@NotBlank(message = “…”)
@Size(min = 3, message = “…”)
private String email2;
				//	omitted




(C) CASAREAL, Inc. All rights reserved.
#glassfish_jp
37
<h:form id="email-form">
<h:inputText value="#{compareBean.email1}"/><br/>
<h:inputText value="#{compareBean.email2}"/><br/>
<h:commandButton value=“ "
action="#{compareBean.submit()}"/>
<f:validateWholeBean value="#{compareBean}"/>
</h:form>
Managed Bean
※<f:validateBean/> validationGroups
(C) CASAREAL, Inc. All rights reserved.
#glassfish_jp
▸ 



▸ 

38
(C) CASAREAL, Inc. All rights reserved.
#glassfish_jp
▸ <f:validateWholeBean> 

▸
39※ h:commandButton
<h:form id="email-form">
<h:inputText value=“…”/><br/>
<h:inputText value=“…”/><br/>
<h:commandButton value=“ " action=“…”/>
<f:validateWholeBean value="#{compareBean}"/>
</h:form>
(C) CASAREAL, Inc. All rights reserved.
#glassfish_jp
40
(C) CASAREAL, Inc. All rights reserved.
#glassfish_jp
▸
▸ @NotBlank @NotEmpty @Email
▸ Optional
▸
41
(C) CASAREAL, Inc. All rights reserved.
#glassfish_jp
▸
▸
▸
▸
42
(C) CASAREAL, Inc. All rights reserved.
#glassfish_jp
▸ 😆
▸
😆
▸
😭
43
(C) CASAREAL, Inc. All rights reserved.
#glassfish_jp
▸
▸
▸
▸
▸
▸
▸
▸
44
(C) CASAREAL, Inc. All rights reserved.
#glassfish_jp
▸
45

More Related Content

What's hot

O/Rマッパーによるトラブルを未然に防ぐ
O/Rマッパーによるトラブルを未然に防ぐO/Rマッパーによるトラブルを未然に防ぐ
O/Rマッパーによるトラブルを未然に防ぐkwatch
 
すごい配列楽しく学ぼう
すごい配列楽しく学ぼうすごい配列楽しく学ぼう
すごい配列楽しく学ぼうxenophobia__
 
ドメイン駆動設計 失敗したことと成功したこと
ドメイン駆動設計 失敗したことと成功したことドメイン駆動設計 失敗したことと成功したこと
ドメイン駆動設計 失敗したことと成功したことBIGLOBE Inc.
 
関数型プログラミングのデザインパターンひとめぐり
関数型プログラミングのデザインパターンひとめぐり関数型プログラミングのデザインパターンひとめぐり
関数型プログラミングのデザインパターンひとめぐりKazuyuki TAKASE
 
これで怖くない!?コードリーディングで学ぶSpring Security #中央線Meetup
これで怖くない!?コードリーディングで学ぶSpring Security #中央線Meetupこれで怖くない!?コードリーディングで学ぶSpring Security #中央線Meetup
これで怖くない!?コードリーディングで学ぶSpring Security #中央線MeetupMasatoshi Tada
 
MQTTとAMQPと.NET
MQTTとAMQPと.NETMQTTとAMQPと.NET
MQTTとAMQPと.NETterurou
 
例外設計における大罪
例外設計における大罪例外設計における大罪
例外設計における大罪Takuto Wada
 
Dockerfile を書くためのベストプラクティス解説編
Dockerfile を書くためのベストプラクティス解説編Dockerfile を書くためのベストプラクティス解説編
Dockerfile を書くためのベストプラクティス解説編Masahito Zembutsu
 
PlaySQLAlchemy: SQLAlchemy入門
PlaySQLAlchemy: SQLAlchemy入門PlaySQLAlchemy: SQLAlchemy入門
PlaySQLAlchemy: SQLAlchemy入門泰 増田
 
劇的改善 Ci4時間から5分へ〜私がやった10のこと〜
劇的改善 Ci4時間から5分へ〜私がやった10のこと〜劇的改善 Ci4時間から5分へ〜私がやった10のこと〜
劇的改善 Ci4時間から5分へ〜私がやった10のこと〜aha_oretama
 
初心者向けWebinar AWSで開発環境を構築しよう
初心者向けWebinar AWSで開発環境を構築しよう初心者向けWebinar AWSで開発環境を構築しよう
初心者向けWebinar AWSで開発環境を構築しようAmazon Web Services Japan
 
RSA暗号運用でやってはいけない n のこと #ssmjp
RSA暗号運用でやってはいけない n のこと #ssmjpRSA暗号運用でやってはいけない n のこと #ssmjp
RSA暗号運用でやってはいけない n のこと #ssmjpsonickun
 
What's new in Spring Batch 5
What's new in Spring Batch 5What's new in Spring Batch 5
What's new in Spring Batch 5ikeyat
 
これからSpringを使う開発者が知っておくべきこと
これからSpringを使う開発者が知っておくべきことこれからSpringを使う開発者が知っておくべきこと
これからSpringを使う開発者が知っておくべきこと土岐 孝平
 
MySQL 5.7の罠があなたを狙っている
MySQL 5.7の罠があなたを狙っているMySQL 5.7の罠があなたを狙っている
MySQL 5.7の罠があなたを狙っているyoku0825
 
DDD sample code explained in Java
DDD sample code explained in JavaDDD sample code explained in Java
DDD sample code explained in Java増田 亨
 
MySQL 5.7にやられないためにおぼえておいてほしいこと
MySQL 5.7にやられないためにおぼえておいてほしいことMySQL 5.7にやられないためにおぼえておいてほしいこと
MySQL 5.7にやられないためにおぼえておいてほしいことyoku0825
 

What's hot (20)

O/Rマッパーによるトラブルを未然に防ぐ
O/Rマッパーによるトラブルを未然に防ぐO/Rマッパーによるトラブルを未然に防ぐ
O/Rマッパーによるトラブルを未然に防ぐ
 
Tackling Complexity
Tackling ComplexityTackling Complexity
Tackling Complexity
 
すごい配列楽しく学ぼう
すごい配列楽しく学ぼうすごい配列楽しく学ぼう
すごい配列楽しく学ぼう
 
Mavenの真実とウソ
Mavenの真実とウソMavenの真実とウソ
Mavenの真実とウソ
 
ドメイン駆動設計 失敗したことと成功したこと
ドメイン駆動設計 失敗したことと成功したことドメイン駆動設計 失敗したことと成功したこと
ドメイン駆動設計 失敗したことと成功したこと
 
関数型プログラミングのデザインパターンひとめぐり
関数型プログラミングのデザインパターンひとめぐり関数型プログラミングのデザインパターンひとめぐり
関数型プログラミングのデザインパターンひとめぐり
 
これで怖くない!?コードリーディングで学ぶSpring Security #中央線Meetup
これで怖くない!?コードリーディングで学ぶSpring Security #中央線Meetupこれで怖くない!?コードリーディングで学ぶSpring Security #中央線Meetup
これで怖くない!?コードリーディングで学ぶSpring Security #中央線Meetup
 
MQTTとAMQPと.NET
MQTTとAMQPと.NETMQTTとAMQPと.NET
MQTTとAMQPと.NET
 
例外設計における大罪
例外設計における大罪例外設計における大罪
例外設計における大罪
 
Dockerfile を書くためのベストプラクティス解説編
Dockerfile を書くためのベストプラクティス解説編Dockerfile を書くためのベストプラクティス解説編
Dockerfile を書くためのベストプラクティス解説編
 
PlaySQLAlchemy: SQLAlchemy入門
PlaySQLAlchemy: SQLAlchemy入門PlaySQLAlchemy: SQLAlchemy入門
PlaySQLAlchemy: SQLAlchemy入門
 
劇的改善 Ci4時間から5分へ〜私がやった10のこと〜
劇的改善 Ci4時間から5分へ〜私がやった10のこと〜劇的改善 Ci4時間から5分へ〜私がやった10のこと〜
劇的改善 Ci4時間から5分へ〜私がやった10のこと〜
 
初心者向けWebinar AWSで開発環境を構築しよう
初心者向けWebinar AWSで開発環境を構築しよう初心者向けWebinar AWSで開発環境を構築しよう
初心者向けWebinar AWSで開発環境を構築しよう
 
RSA暗号運用でやってはいけない n のこと #ssmjp
RSA暗号運用でやってはいけない n のこと #ssmjpRSA暗号運用でやってはいけない n のこと #ssmjp
RSA暗号運用でやってはいけない n のこと #ssmjp
 
What's new in Spring Batch 5
What's new in Spring Batch 5What's new in Spring Batch 5
What's new in Spring Batch 5
 
Monad tutorial
Monad tutorialMonad tutorial
Monad tutorial
 
これからSpringを使う開発者が知っておくべきこと
これからSpringを使う開発者が知っておくべきことこれからSpringを使う開発者が知っておくべきこと
これからSpringを使う開発者が知っておくべきこと
 
MySQL 5.7の罠があなたを狙っている
MySQL 5.7の罠があなたを狙っているMySQL 5.7の罠があなたを狙っている
MySQL 5.7の罠があなたを狙っている
 
DDD sample code explained in Java
DDD sample code explained in JavaDDD sample code explained in Java
DDD sample code explained in Java
 
MySQL 5.7にやられないためにおぼえておいてほしいこと
MySQL 5.7にやられないためにおぼえておいてほしいことMySQL 5.7にやられないためにおぼえておいてほしいこと
MySQL 5.7にやられないためにおぼえておいてほしいこと
 

Similar to Java EE 8新機能解説 -Bean Validation 2.0編-

Java EEでもOAuth 2.0!~そしてPayara Micro on Cloud Foundryで遊ぶ~
Java EEでもOAuth 2.0!~そしてPayara Micro on Cloud Foundryで遊ぶ~Java EEでもOAuth 2.0!~そしてPayara Micro on Cloud Foundryで遊ぶ~
Java EEでもOAuth 2.0!~そしてPayara Micro on Cloud Foundryで遊ぶ~Masatoshi Tada
 
Spring Bootの本当の理解ポイント #jjug
Spring Bootの本当の理解ポイント #jjugSpring Bootの本当の理解ポイント #jjug
Spring Bootの本当の理解ポイント #jjugMasatoshi Tada
 
ReactiveだけじゃないSpring 5 & Spring Boot 2新機能解説
ReactiveだけじゃないSpring 5 & Spring Boot 2新機能解説ReactiveだけじゃないSpring 5 & Spring Boot 2新機能解説
ReactiveだけじゃないSpring 5 & Spring Boot 2新機能解説Masatoshi Tada
 
Spring Data JPAによるデータアクセス徹底入門 #jsug
Spring Data JPAによるデータアクセス徹底入門 #jsugSpring Data JPAによるデータアクセス徹底入門 #jsug
Spring Data JPAによるデータアクセス徹底入門 #jsugMasatoshi Tada
 
JSUG SpringOne 2017報告会
JSUG SpringOne 2017報告会JSUG SpringOne 2017報告会
JSUG SpringOne 2017報告会Masatoshi Tada
 
保守・追加開発に必要な「Springの正しい知識」とは?20171109
保守・追加開発に必要な「Springの正しい知識」とは?20171109保守・追加開発に必要な「Springの正しい知識」とは?20171109
保守・追加開発に必要な「Springの正しい知識」とは?20171109CASAREAL, Inc.
 
とにかく分かりづらいTwelve-Factor Appの解説を試みる
とにかく分かりづらいTwelve-Factor Appの解説を試みるとにかく分かりづらいTwelve-Factor Appの解説を試みる
とにかく分かりづらいTwelve-Factor Appの解説を試みるMasatoshi Tada
 

Similar to Java EE 8新機能解説 -Bean Validation 2.0編- (7)

Java EEでもOAuth 2.0!~そしてPayara Micro on Cloud Foundryで遊ぶ~
Java EEでもOAuth 2.0!~そしてPayara Micro on Cloud Foundryで遊ぶ~Java EEでもOAuth 2.0!~そしてPayara Micro on Cloud Foundryで遊ぶ~
Java EEでもOAuth 2.0!~そしてPayara Micro on Cloud Foundryで遊ぶ~
 
Spring Bootの本当の理解ポイント #jjug
Spring Bootの本当の理解ポイント #jjugSpring Bootの本当の理解ポイント #jjug
Spring Bootの本当の理解ポイント #jjug
 
ReactiveだけじゃないSpring 5 & Spring Boot 2新機能解説
ReactiveだけじゃないSpring 5 & Spring Boot 2新機能解説ReactiveだけじゃないSpring 5 & Spring Boot 2新機能解説
ReactiveだけじゃないSpring 5 & Spring Boot 2新機能解説
 
Spring Data JPAによるデータアクセス徹底入門 #jsug
Spring Data JPAによるデータアクセス徹底入門 #jsugSpring Data JPAによるデータアクセス徹底入門 #jsug
Spring Data JPAによるデータアクセス徹底入門 #jsug
 
JSUG SpringOne 2017報告会
JSUG SpringOne 2017報告会JSUG SpringOne 2017報告会
JSUG SpringOne 2017報告会
 
保守・追加開発に必要な「Springの正しい知識」とは?20171109
保守・追加開発に必要な「Springの正しい知識」とは?20171109保守・追加開発に必要な「Springの正しい知識」とは?20171109
保守・追加開発に必要な「Springの正しい知識」とは?20171109
 
とにかく分かりづらいTwelve-Factor Appの解説を試みる
とにかく分かりづらいTwelve-Factor Appの解説を試みるとにかく分かりづらいTwelve-Factor Appの解説を試みる
とにかく分かりづらいTwelve-Factor Appの解説を試みる
 

More from Masatoshi Tada

Pivotal認定講師によるSpring Framework 5.1 & Spring Boot 2.1ハンズオン! #jjug_ccc
Pivotal認定講師によるSpring Framework 5.1 & Spring Boot 2.1ハンズオン! #jjug_cccPivotal認定講師によるSpring Framework 5.1 & Spring Boot 2.1ハンズオン! #jjug_ccc
Pivotal認定講師によるSpring Framework 5.1 & Spring Boot 2.1ハンズオン! #jjug_cccMasatoshi Tada
 
基礎からのOAuth 2.0とSpring Security 5.1による実装
基礎からのOAuth 2.0とSpring Security 5.1による実装基礎からのOAuth 2.0とSpring Security 5.1による実装
基礎からのOAuth 2.0とSpring Security 5.1による実装Masatoshi Tada
 
初めてでも30分で分かるSpring 5 & Spring Boot 2オーバービュー
初めてでも30分で分かるSpring 5 & Spring Boot 2オーバービュー初めてでも30分で分かるSpring 5 & Spring Boot 2オーバービュー
初めてでも30分で分かるSpring 5 & Spring Boot 2オーバービューMasatoshi Tada
 
Getting start Java EE Action-Based MVC with Thymeleaf
Getting start Java EE Action-Based MVC with ThymeleafGetting start Java EE Action-Based MVC with Thymeleaf
Getting start Java EE Action-Based MVC with ThymeleafMasatoshi Tada
 
Java EEハンズオン資料 JJUG CCC 2015 Fall
Java EEハンズオン資料 JJUG CCC 2015 FallJava EEハンズオン資料 JJUG CCC 2015 Fall
Java EEハンズオン資料 JJUG CCC 2015 FallMasatoshi Tada
 
Java EE 8先取り!MVC 1.0入門 [EDR2対応版] 2015-10-10更新
Java EE 8先取り!MVC 1.0入門 [EDR2対応版] 2015-10-10更新Java EE 8先取り!MVC 1.0入門 [EDR2対応版] 2015-10-10更新
Java EE 8先取り!MVC 1.0入門 [EDR2対応版] 2015-10-10更新Masatoshi Tada
 
NetBeansでかんたんJava EE ○分間クッキング! #kuwaccho lt
NetBeansでかんたんJava EE ○分間クッキング! #kuwaccho ltNetBeansでかんたんJava EE ○分間クッキング! #kuwaccho lt
NetBeansでかんたんJava EE ○分間クッキング! #kuwaccho ltMasatoshi Tada
 
ステップ・バイ・ステップで学ぶラムダ式・Stream api入門 #jjug ccc #ccc h2
ステップ・バイ・ステップで学ぶラムダ式・Stream api入門 #jjug ccc #ccc h2ステップ・バイ・ステップで学ぶラムダ式・Stream api入門 #jjug ccc #ccc h2
ステップ・バイ・ステップで学ぶラムダ式・Stream api入門 #jjug ccc #ccc h2Masatoshi Tada
 
JPAの同時実行制御とロック20140518 #ccc_r15 #jjug_ccc
JPAの同時実行制御とロック20140518 #ccc_r15 #jjug_cccJPAの同時実行制御とロック20140518 #ccc_r15 #jjug_ccc
JPAの同時実行制御とロック20140518 #ccc_r15 #jjug_cccMasatoshi Tada
 

More from Masatoshi Tada (9)

Pivotal認定講師によるSpring Framework 5.1 & Spring Boot 2.1ハンズオン! #jjug_ccc
Pivotal認定講師によるSpring Framework 5.1 & Spring Boot 2.1ハンズオン! #jjug_cccPivotal認定講師によるSpring Framework 5.1 & Spring Boot 2.1ハンズオン! #jjug_ccc
Pivotal認定講師によるSpring Framework 5.1 & Spring Boot 2.1ハンズオン! #jjug_ccc
 
基礎からのOAuth 2.0とSpring Security 5.1による実装
基礎からのOAuth 2.0とSpring Security 5.1による実装基礎からのOAuth 2.0とSpring Security 5.1による実装
基礎からのOAuth 2.0とSpring Security 5.1による実装
 
初めてでも30分で分かるSpring 5 & Spring Boot 2オーバービュー
初めてでも30分で分かるSpring 5 & Spring Boot 2オーバービュー初めてでも30分で分かるSpring 5 & Spring Boot 2オーバービュー
初めてでも30分で分かるSpring 5 & Spring Boot 2オーバービュー
 
Getting start Java EE Action-Based MVC with Thymeleaf
Getting start Java EE Action-Based MVC with ThymeleafGetting start Java EE Action-Based MVC with Thymeleaf
Getting start Java EE Action-Based MVC with Thymeleaf
 
Java EEハンズオン資料 JJUG CCC 2015 Fall
Java EEハンズオン資料 JJUG CCC 2015 FallJava EEハンズオン資料 JJUG CCC 2015 Fall
Java EEハンズオン資料 JJUG CCC 2015 Fall
 
Java EE 8先取り!MVC 1.0入門 [EDR2対応版] 2015-10-10更新
Java EE 8先取り!MVC 1.0入門 [EDR2対応版] 2015-10-10更新Java EE 8先取り!MVC 1.0入門 [EDR2対応版] 2015-10-10更新
Java EE 8先取り!MVC 1.0入門 [EDR2対応版] 2015-10-10更新
 
NetBeansでかんたんJava EE ○分間クッキング! #kuwaccho lt
NetBeansでかんたんJava EE ○分間クッキング! #kuwaccho ltNetBeansでかんたんJava EE ○分間クッキング! #kuwaccho lt
NetBeansでかんたんJava EE ○分間クッキング! #kuwaccho lt
 
ステップ・バイ・ステップで学ぶラムダ式・Stream api入門 #jjug ccc #ccc h2
ステップ・バイ・ステップで学ぶラムダ式・Stream api入門 #jjug ccc #ccc h2ステップ・バイ・ステップで学ぶラムダ式・Stream api入門 #jjug ccc #ccc h2
ステップ・バイ・ステップで学ぶラムダ式・Stream api入門 #jjug ccc #ccc h2
 
JPAの同時実行制御とロック20140518 #ccc_r15 #jjug_ccc
JPAの同時実行制御とロック20140518 #ccc_r15 #jjug_cccJPAの同時実行制御とロック20140518 #ccc_r15 #jjug_ccc
JPAの同時実行制御とロック20140518 #ccc_r15 #jjug_ccc
 

Recently uploaded

Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesZilliz
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 

Recently uploaded (20)

Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 

Java EE 8新機能解説 -Bean Validation 2.0編-

  • 1. (C) CASAREAL, Inc. All rights reserved. #glassfish_jp 1
  • 2. (C) CASAREAL, Inc. All rights reserved. #glassfish_jp ▸ ▸ ▸ ▸ 2
  • 3. (C) CASAREAL, Inc. All rights reserved. #glassfish_jp ▸ ▸ ▸ 
 ▸ ▸ 3
  • 4. (C) CASAREAL, Inc. All rights reserved. #glassfish_jp ▸ 4
  • 5. (C) CASAREAL, Inc. All rights reserved. #glassfish_jp ▸ ▸ ▸ ▸ ▸ 💖 5
  • 6. (C) CASAREAL, Inc. All rights reserved. #glassfish_jp 6
  • 7. (C) CASAREAL, Inc. All rights reserved. #glassfish_jp 7
  • 8. (C) CASAREAL, Inc. All rights reserved. #glassfish_jp ▸ ▸ ▸ 8
  • 9. (C) CASAREAL, Inc. All rights reserved. #glassfish_jp ▸ ▸ 
 ▸ 9
  • 10. (C) CASAREAL, Inc. All rights reserved. #glassfish_jp 10 public class HelloDto { @NotBlank(message = "{hello.notblank}") private String message; // getter/setter } @Path("/hello") public class HelloResource { @POST public Response post(@Valid HelloDto helloDto) { // } } 

  • 11. (C) CASAREAL, Inc. All rights reserved. #glassfish_jp ▸ 11 hello.notblank = ▸ ▸ hello.notblank = Message is required hello.notblank = ValidationMessages_ja.properties ValidationMessages_en.properties
  • 12. (C) CASAREAL, Inc. All rights reserved. #glassfish_jp 12 $ curl -v -X POST -H "Content-Type: application/json” -d ‘{"message":""}' http://localhost:8080/api/hello > POST /api/hello HTTP/1.1 > … > < HTTP/1.1 400 Bad Request < … < { "errorType":" ", "messages":[" "] } ※JSON ExceptionMapper
  • 13. (C) CASAREAL, Inc. All rights reserved. #glassfish_jp ▸ 13 Bean Validation 

  • 14. (C) CASAREAL, Inc. All rights reserved. #glassfish_jp 14
  • 15. (C) CASAREAL, Inc. All rights reserved. #glassfish_jp ▸ 👏 ▸ 15
  • 16. (C) CASAREAL, Inc. All rights reserved. #glassfish_jp ▸ ▸ ▸ ▸ ▸ 16
  • 17. (C) CASAREAL, Inc. All rights reserved. #glassfish_jp 17
  • 18. (C) CASAREAL, Inc. All rights reserved. #glassfish_jp ▸ @NotNull ▸ @Null ▸ @NotEmpty ▸ @NotBlank ▸ @AssertTrue ▸ @AssertFalse ▸ @Size ▸ @Pattern 18 ▸ @Email ▸ @Digits ▸ @DecimalMax ▸ @DecimalMin ▸ @Max ▸ @Min ▸ @Positive ▸ @PositiveOrZero ▸ @Negative ▸ @NegativeOrZero ▸ @Past ▸ @PastOrPresent ▸ @Future ▸ @FutureOrPresent ※
  • 19. (C) CASAREAL, Inc. All rights reserved. #glassfish_jp 19 @NotBlank CharSequence null ❌ @NotEmpty 
 null 0 ❌ @Email CharSequence ❌ @Positive ❌ @PositiveOrZero 0 ❌
  • 20. (C) CASAREAL, Inc. All rights reserved. #glassfish_jp 20 @Negative ❌ @NegativeOrZero 0 ❌ @PastOrPresent Date Calendar java.time.* ❌ @FutureOrPresent Date Calendar java.time.* ❌
  • 21. (C) CASAREAL, Inc. All rights reserved. #glassfish_jp ▸ @NotBlank @NotEmpty @Email 👏 ▸ 
 ▸ 👏 ▸ @Past @PastOrPresent @Future @FutureOrPresent 21
  • 22. (C) CASAREAL, Inc. All rights reserved. #glassfish_jp ▸ @Past 
 👏 ▸ @Max/@Positive 
 javax.money.MonetaryAmount 👏 ▸ 
 22
  • 23. (C) CASAREAL, Inc. All rights reserved. #glassfish_jp 23
  • 24. (C) CASAREAL, Inc. All rights reserved. #glassfish_jp 24 public class Sample { private Optional<@Size(min = 3) String> optionalString; private List<@NotNull String> list = new ArrayList<>(); // omitted } ▸ 👏 ▸ ※JSR Container element constraints
  • 25. (C) CASAREAL, Inc. All rights reserved. #glassfish_jp ▸ OptionalXxx java.util.OptionalInt 
 XxxProperty IntegerProperty 
 👏 25 public class Sample { @Max(10) private OptionalInt optionalInt; // omitted }
  • 26. (C) CASAREAL, Inc. All rights reserved. #glassfish_jp 26 @Test public void test() { Sample sample = new Sample(); sample.addToOptionalString(“aa"); // 3 sample.addToList(null); // not null sample.addToOptionalInt(20); // 10 // Set<ConstraintViolation<Sample>> violations = validator.validate(sample); // assertEquals(3, violations.size()); }
  • 27. (C) CASAREAL, Inc. All rights reserved. #glassfish_jp 27 @Test public void test2() { Sample sample = new Sample(); sample.addToList(null); // not null 1 sample.addToList(null); // not null 2 // Set<ConstraintViolation<Sample>> violations = validator.validate(sample); // assertEquals(2, violations.size()); } ▸
  • 28. (C) CASAREAL, Inc. All rights reserved. #glassfish_jp 28
  • 29. (C) CASAREAL, Inc. All rights reserved. #glassfish_jp @Max(value = 100, groups = Group1.class) @Max(value = 200, groups = Group2.class) int someValue; ▸ ▸ @Xxx.List 👏 29 @Max.List({ @Max(value = 100, groups = Group1.class), @Max(value = 200, groups = Group2.class) }) int someValue;
  • 30. (C) CASAREAL, Inc. All rights reserved. #glassfish_jp ▸ ParameterNameProvider 👏 ▸ -parameters 30
  • 31. (C) CASAREAL, Inc. All rights reserved. #glassfish_jp ▸ ConstraintValidator initialize() ▸ 31
  • 32. (C) CASAREAL, Inc. All rights reserved. #glassfish_jp 32
  • 33. (C) CASAREAL, Inc. All rights reserved. #glassfish_jp ▸ 👏 33
  • 34. (C) CASAREAL, Inc. All rights reserved. #glassfish_jp 34 <web-app …> <context-param> <param-name> javax.faces.validator.ENABLE_VALIDATE_WHOLE_BEAN </param-name> <param-value>true</param-value> </context-param> <!-- omitted --> </web-app> 
 

  • 35. (C) CASAREAL, Inc. All rights reserved. #glassfish_jp 35 public class EqualsValidator implements ConstraintValidator<Equals, Object> { @Override public boolean isValid(Object obj, ConstraintValidatorContext context) { // 2 // true } @Constraint(validatedBy = EqualsValidator.class) public @interface Equals { String property1(); // 1 String property2(); // 2
  • 36. (C) CASAREAL, Inc. All rights reserved. #glassfish_jp 36 @Named @ViewScoped @Equals(property1 = "email1", property2 = "email2", message = “…”) public class CompareBean implements Serializable { @NotBlank(message = “…”) @Size(min = 3, message = “…”) private String email1; @NotBlank(message = “…”) @Size(min = 3, message = “…”) private String email2; // omitted 
 

  • 37. (C) CASAREAL, Inc. All rights reserved. #glassfish_jp 37 <h:form id="email-form"> <h:inputText value="#{compareBean.email1}"/><br/> <h:inputText value="#{compareBean.email2}"/><br/> <h:commandButton value=“ " action="#{compareBean.submit()}"/> <f:validateWholeBean value="#{compareBean}"/> </h:form> Managed Bean ※<f:validateBean/> validationGroups
  • 38. (C) CASAREAL, Inc. All rights reserved. #glassfish_jp ▸ 
 
 ▸ 
 38
  • 39. (C) CASAREAL, Inc. All rights reserved. #glassfish_jp ▸ <f:validateWholeBean> 
 ▸ 39※ h:commandButton <h:form id="email-form"> <h:inputText value=“…”/><br/> <h:inputText value=“…”/><br/> <h:commandButton value=“ " action=“…”/> <f:validateWholeBean value="#{compareBean}"/> </h:form>
  • 40. (C) CASAREAL, Inc. All rights reserved. #glassfish_jp 40
  • 41. (C) CASAREAL, Inc. All rights reserved. #glassfish_jp ▸ ▸ @NotBlank @NotEmpty @Email ▸ Optional ▸ 41
  • 42. (C) CASAREAL, Inc. All rights reserved. #glassfish_jp ▸ ▸ ▸ ▸ 42
  • 43. (C) CASAREAL, Inc. All rights reserved. #glassfish_jp ▸ 😆 ▸ 😆 ▸ 😭 43
  • 44. (C) CASAREAL, Inc. All rights reserved. #glassfish_jp ▸ ▸ ▸ ▸ ▸ ▸ ▸ ▸ 44
  • 45. (C) CASAREAL, Inc. All rights reserved. #glassfish_jp ▸ 45