Search code examples
jsfuser-interfaceannotationscomponentspojo

Controlling the UI Component from POJO annotations


I'm working in a Java EE web application using Hibernate, Spring, JSF and Primefaces.

My Question is how can I control the UI components (jsf and primefaces components) using POJO annotations.
Is there any framework I can add to my project to do this?

example :

class user {
   @NotNull @Max=100
   public String name;
}

The UI component associated with the name attribut must validate the string entred (not null and not exceding 100 char.)


Solution

  • This is called bean validation, also known as JSR-303. The reference implementation is the Hibernate Validator. This is already bundled in every Java EE 6 application server complying the web profile, such as Glassfish 3, JBoss AS 6/7, etc. This is not bundled in barebones JSP/Servlet containers such as Tomcat, Jetty, etc. If you target those containers, you'd need to download the bean validation libraries and drop in webapp's /WEB-INF/lib yourself.

    See also: