Search code examples
springhibernatevalidationspring-annotations

Annotation for validating checkbox in Spring


I have some checkboxes in my Spring application. I am using the size annotation to check whether at least one checkbox has been clicked.

@Column(name = "workallot") 
@Size(min=1, max=6)
private Integer[] workAllotment;        

It is generating the message for six checkboxes as below

size must be between 1 and 6

But I want it to be like

At least One Checkbox must be checked

How do i customize this message ?


Solution

  •  @Size(min=1, max=6 ,message = "At least One Checkbox must be checked")
    

    Here is documentation which provides all parameters which annotation takes:

    https://docs.oracle.com/javaee/7/api/javax/validation/constraints/Size.html

    Also here is similar question :

    How to customize Hibernate @Size error message to indicate length of entered field