Quark Engine Parameter Validation - Part 5

In Quark Engine last update version 1.4.0. support for JSR-380 was added. JSR-380 is a Bean Validation Specification allowing easy input parameters constraints validations making web calls even more safe.

JSR-380 Validation is an important part of the Java ecosystem and supported by default in standardized REST specification used for controlling and validating data constraints. Now it is available in Quark Engine also.

Usage is quite simple. Only what is required is to activate validation and add a few validations annotations to method parameters. We updated DemoController with only a few small changes as shown below.

@ExtJSMethod(value = "saveUser", validate = true)
public ExtJSObjectResponse<UserModel> save(
		@NotNull @NotBlank 
		@Size(min = 5, max = 20, message = "User must be between 5 and 20 characters long")
		final String name, 

		@NotNull @NotBlank @Email
		final String email) {

	final ExtJSObjectResponse<UserModel> resp = new ExtJSObjectResponse<>(true, null);
		
	final UserModel model = getUser(name, email);
	resp.setData(model);
	
	return resp;
}

Notice @ExtJSMethod, it is a little bit different than in the rest of provided demos. To enable validations, simply set validate=true.

For validation framework specification and manual follow link Bean Validation Specification.