Skip to content

zoowii/form-utils

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FormUtils

Yet another form validator library

Usage

First, deploy this project to your local maven repository
then add the dependency:
<dependency>
  <groupId>com.zoowii</groupId>
  <artifactId>formutils</artifactId>
  <version>1.0.3</version>
</dependency>

// define the form class
public class DemoForm {
    @NotNull
    @Length(min = 4, max = 30)
    private String name;
    @Email
    @NotEmpty(message = "The email can't be empty")
    private String email;
    @Min(18)
    @Max(150)
    private int age;
    @Past
    private Date createTime;

    @Valid
    private DemoForm subForm;

    ... getters and setters
}

// validate form
Validator validator = ValidatorFactory.getValidator();
DemoForm demoForm = new DemoForm();
demoForm.setName(null);
demoForm.setEmail("test@email.com");
demoForm.setAge(200);
demoForm.setSubForm(new DemoForm());
BindingResult bindingResult = validator.validate(demoForm);
Assert.assertEquals(bindingResult.getErrorCount(), 5);

// you can also define your own validation annotation and the mapped constrait class
// just extend the Constrait<T extends Annotation> class

About

Yet another simple form validator library

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages