Question

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 ?

Was it helpful?

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...

OTHER TIPS

It depends on a few factors but the best you can do is to look for a README.md file inside the archive you downloaded. In my case that was hibernate-validator-5.4.0.Final.jar from the JBoss site. In there, among other things there's a section called "Using Hibernate Validator"

Using Hibernate Validator

In case you use the distribution archive from the download site, copy dist/hibernate-validator-<version>.jar together with all jar files from dist/lib/required into the classpath of your application. For the purposes of logging, Hibernate Validator uses the JBoss Logging API, an abstraction layer which supports several logging solutions such (e.g. log4j or the logging framework provided by the JDK) as implementation. Just add a supported logging library to the classpath (e.g. log4j-<version>.jar) and JBoss Logging will delegate any log requests to that provider.

+1 for the other answer that teaches you how to create a user defined library so you can group those files neatly into one convenient bundle.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top