validation - Spring MVC validate a checkboxes list -


i have following beans:

public class codedentity {     private string name;     private string code;     // getters , setters }  public class myproduct {     @javax.validation.constraints.size(min = 1)     private list<codedentity> codedentities;     // getters , setters } 

as see codedentities list must have @ least 1 element.

in controller validate size of list :

@requestmapping(value = "/**", method = requestmethod.post) public string submit(@valid final myproduct myproduct, final bindingresult result,         final model model) {     // ... } 

and jsp :

<c:foreach items="${codedentitieslist}" var="codedentity" varstatus="loopstatus"             <form:checkbox path="myproduct.codedentities[${loopstatus.index}]" value="${codedentity.code}" cssclass="checkbox" /> </c:foreach> 

the problem here following : when submit jsp without checking checkbox, spring mvc returns non-empty list containing "null" elements. , because of this, validation fails.

how can tell spring-mvc return empty list instead of list full of "null" elements ? or @ least there way can validate constraint ?

might easier javascript, otherwise if want pure java implementation, i'd implement own annotation. @listcontainsvalue, shouldn't hard implement. if need example of how implement own validation annotation, there's 1 located here:

cross field validation hibernate validator (jsr 303)


Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -