Search code examples
javajpavaadinvaadin7

What are the jars necessary to bean validation?


I'm trying validating my beans using bean validator. The problem is I don't know which libraries(jar) are necessary to validation.

I'm using.

Vaadin 7, BeanFieldGroup and EclipseLink

/** class of MyBean */
public class MyBean{
    @Id
@GeneratedValue 
    private Long id;

    @NotNull
    @NotEmpty
    @Size(min=5, max=50, message="Min = 5 and Max = 50, this field is not empty")
    private String name;

    @Email
    @NotEmpty
    private String email; 

}

Any idea ?


Solution

  • Follow these step-by-step instructions on how to download and configure Hibernate Validator in your Eclipse project:

    1. Download the following Hibernate Validator files from JBoss Repository:
    2. Select your project's root in Eclipse
    3. Go to Window -> Preferences -> Java -> Build Path -> User Libraries view
    4. Click New... button on the right to open New User Library window:
      • enter your library name (i.e. Hibernate Validator 5.1.0)
      • click OK button to accept
    5. Click Add External JARs... button on the right to open JAR Selection window:
      • select the previously downloaded validation-api-1.1.0.Final.jar and hibernate-validator-5.1.0.Final.jar files
      • click Open button to add them into Hibernate Validator 5.1.0 library
    6. Select Source Attachment under validation-api-1.1.0.Final.jar tree node
    7. Click Edit... button on the left to open Source Attachment Configuration window:
      • select External location radio button
      • click External File... button to open JAR/ZIP File Selection window
      • select the previously downloaded validation-api-1.1.0.Final-sources.jar
      • click Open button to set up Location path in the parent window
      • click OK button to accept
    8. Select Source Attachment under validation-api-1.1.0.Final.jar tree node
    9. Click Edit... button on the left to open Javadoc For 'hibernate-validator-5.1.0.Final.jar' window:
      • select Javadoc in archive radio button
      • select External File... radio button
      • click Browse... button to open Javadoc Archice Selection window
      • select the previously downloaded validation-api-1.1.0.Final-javadoc.jar
      • click Open button to set up Archive path in the parent window
      • click OK button to accept
    10. Repeat steps 6-9 for hibernate-validator-5.1.0.Final.jar
    11. Click OK button in User Libraries view.

    In a moment Eclipse is ready to work with Bean Validation constraints.

    In fact you could end up the configuration on step 5) as this is all you need to make Bean Validation work, however development is much more comfortable if a given main .jar is associated with its corresponding -javadoc and -sources libraries as it gives you opportunity to:

    • view Javadoc comments - F2
    • view source files - F3

    respectively for the selected constraint in Eclipse Java Editor.


    Now, imagine you can achieve the same with a single step (well, almost) using Maven but that's another story for another time...