title: How to do the Hibernate validation on the nested list objects?
body: <p>I need to validate the objects which are stored in the list on my form bean object.</p>
  
  <p>Below is my form bean object.</p>
  
  <pre><code>public class Role implements java.io.Serializable {
  
      // Fields    
      private int roleId;
  
      @NotBlank
      private String roleName;
  
      private boolean active;
  
      @Valid
      private List&lt;Module&gt; modules;
  
      // getters anfd setters
  }
  </code></pre>
  
  <p>and below is my object which is present in the list of my main form bean object</p>
  
  <pre><code>public class Module implements Serializable {
  
      private int id;
  
      @NotBlank
      private String moduleName;
  
      // other properties and getters and setters
  }
  </code></pre>
  
  <p>Below is my properties file</p>
  
  <pre><code># -- Role form -- 
  NotBlank.role.roleName=Role Name can not be blank.
  NotBlank.module.moduleName=Module Name can not be blank.
  </code></pre>
  
  <p>Below is My JSP page, the form consists of a role name and modules which can be added to the role.</p>
  
  <pre><code>    &lt;table border="0" class="section_tbl2"&gt;
      &lt;tr&gt;
          &lt;td width="150px" valign="top"&gt;
              &lt;spring:message code="dmx.role.form.label.name"/&gt;
          &lt;/td&gt;
          &lt;td width="10px"&gt;:&lt;/td&gt;
          &lt;td&gt;
              &lt;form:input class="txtinput" id="roleName" path="roleName" maxlength="50"/&gt;      &lt;form:errors path="roleName" cssClass="error"/&gt;
  
          &lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;&lt;td colspan="3" height="8px"&gt;&lt;/td&gt;&lt;/tr&gt;
  
      &lt;tr&gt;
          &lt;td width="150px" vAlign="top"&gt;
              Modules
          &lt;/td&gt;
          &lt;td width="10px" vAlign="top"&gt;:&lt;/td&gt;
          &lt;td&gt;
  
              &lt;table&gt;
                  &lt;tr&gt;
                      &lt;td&gt;
                          &lt;input type="button" value="&lt;spring:message code="dmx.role.form.button.addModule.label"/&gt;" onclick="return addModuleRow();"&gt;&lt;/input&gt;
                      &lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;&lt;td&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
              &lt;/table&gt;
  
              &lt;table cellpadding="0" cellspacing="0" border="0" class="tblstyle1" id="moduleTable"&gt;
                  &lt;thead&gt;
                      &lt;tr&gt;
                          &lt;th class="fst" width="200px"&gt;
                              &lt;spring:message code="dmx.role.form.label.moduleName"/&gt;
                          &lt;/th&gt;
                          &lt;th width="50px"&gt;&lt;spring:message code="dmx.role.form.label.create"/&gt;&lt;/th&gt;
                          &lt;th width="50px"&gt;&lt;spring:message code="dmx.role.form.label.update"/&gt;&lt;/th&gt;
                          &lt;th width="50px"&gt;&lt;spring:message code="dmx.role.form.label.delete"/&gt;&lt;/th&gt;
                          &lt;th width="30px"&gt;&lt;/th&gt;
                      &lt;/tr&gt;
                  &lt;/thead&gt;
                  &lt;tbody id="moduleTBody"&gt;
                      &lt;c:forEach items="${role.modules}" var="module" varStatus="status" &gt;
                          &lt;c:set var="moduleCounter" value="${status.index}"/&gt;
                          &lt;tr id="moduleRowId_${moduleCounter}"&gt;
                              &lt;td class="fst txt-center"&gt;
                                  &lt;form:select onchange="checkIfThisModuleAlreadySelected(this);" class="seloption" id="selectedModule_${moduleCounter}" path="modules[${moduleCounter}].id"&gt;
                                      &lt;form:option value="" label="-- Select Module --"/&gt;
                                      &lt;form:options items="${moduleList}" itemLabel="moduleName" itemValue="id" /&gt;
                                  &lt;/form:select&gt;
                              &lt;/td&gt;
                              &lt;td class="txt-center"&gt;
                                  &lt;form:checkbox id="create_${moduleCounter}" path="modules[${moduleCounter}].create"/&gt;
                              &lt;/td&gt;
                              &lt;td class="txt-center"&gt;
                                  &lt;form:checkbox id="update_${moduleCounter}" path="modules[${moduleCounter}].update"/&gt;
                              &lt;/td&gt;
                              &lt;td class="txt-center"&gt;
                                  &lt;form:checkbox id="delete_${moduleCounter}" path="modules[${moduleCounter}].delete"/&gt;
                              &lt;td class="txt-center"&gt;
                                  &lt;input class="delbtn" id="moduleDelBtn_${moduleCounter}" name="moduleDelBtn[${moduleCounter}]" type="button" onclick="delModuleRow(${moduleCounter});"&gt;
                              &lt;/td&gt;
                          &lt;/tr&gt;
                      &lt;/c:forEach&gt;
                  &lt;/tbody&gt;    
              &lt;/table&gt;                
          &lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;&lt;td colspan="3" height="3px"&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>I can successfully validate the role name i.e. when role name is blank I get an error message but when module is not selected i do not get any error message. </p>
  
  <p>Please help</p>