| Java EE 7 SDK |
This sample application demonstrates how to inject beans with validation constraints.
This sample application injects a bean in a servlet with annotations for validation constraints. The constraints are validated at run time using the input/output provided.
@Named(value="Bean1")
public class Bean1 {
public @NotNull String sayHello(@NotNull @Size(max=5) String arg) {
return "Hello, " + arg + " !";
}
}
The example is divided into 3 scenarios:
arg is test, which passes both constraints placed on the input. arg is null, which violates the @NotNull constraint. arg is testxyz, which violates the @Size(max=5) constraint.The servlet at http://<host>:<port>/<context-root>/ValidationServlet runs these three scenarios and presents the results as HTML output.
Perform the following steps to build, deploy, and run the application:
app_dir is the sample application base directory: samples_install_dir/javaee7/cdi/bean-validation.app_dir.run outcome.
mvn clean verify cargo:run
clean outcome to undeploy the sample application and to remove the temporary directories such as build and dist.
mvn clean
If you have problems when running the application, refer to the troubleshooting document.
Copyright © 1997-2013 Oracle and/or its affiliates. All rights reserved.