uCosminexus Application Server, Common Container Functionality Guide
This subsection describes procedures for using Bean Validation from CDI.
To perform the validation processing using Bean Validation with CDI:
The following is an example of implementation using Bean Validation from CDI.
The first example shows an implementation of the servlet that registers the information for which validation is required.
public class EmployeeServBv extends HttpServlet{
@Inject private ValidatorFactory validatorFactory;
@Inject BV_CDI bean;
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException{
Validator validator = validatorFactory.getValidator();
validator.validate(bean);
}
}
|
In this example, the Bean Validation annotation is applied in the BV_CDI bean.
The next example shows an implementation of the validation definition for the Bean that stores the data to be validated.
import javax.validation.constraints.NotNull;
public class BV_CDI{
@NotNull
private String name;
public String getName(){
return name;
}
public void setName(String name){
this.name = name;
}
}
|
All Rights Reserved. Copyright (C) 2013, Hitachi, Ltd.