2011-09-23 14 views
7

मैं वस्तुओं जो मेरे प्रपत्र सेम वस्तु पर सूची में जमा हो जाती मान्य करने के लिए की जरूरत है।कैसे नेस्टेड सूची वस्तुओं पर हाइबरनेट सत्यापन करना है?

नीचे मेरा फॉर्म बीन ऑब्जेक्ट है।

public class Role implements java.io.Serializable { 

    // Fields  
    private int roleId; 

    @NotBlank 
    private String roleName; 

    private boolean active; 

    @Valid 
    private List<Module> modules; 

    // getters anfd setters 
} 

और नीचे

public class Module implements Serializable { 

    private int id; 

    @NotBlank 
    private String moduleName; 

    // other properties and getters and setters 
} 

नीचे मेरी गुण फ़ाइल है

# -- Role form -- 
NotBlank.role.roleName=Role Name can not be blank. 
NotBlank.module.moduleName=Module Name can not be blank. 

नीचे मेरे JSP पेज, है मेरी वस्तु जो अपने मुख्य रूप सेम वस्तु की सूची में मौजूद है प्रपत्र में एक भूमिका का नाम और मॉड्यूल शामिल है जिसे भूमिका में जोड़ा जा सकता है।

<table border="0" class="section_tbl2"> 
    <tr> 
     <td width="150px" valign="top"> 
      <spring:message code="dmx.role.form.label.name"/> 
     </td> 
     <td width="10px">:</td> 
     <td> 
      <form:input class="txtinput" id="roleName" path="roleName" maxlength="50"/>  <form:errors path="roleName" cssClass="error"/> 

     </td> 
    </tr> 
    <tr><td colspan="3" height="8px"></td></tr> 

    <tr> 
     <td width="150px" vAlign="top"> 
      Modules 
     </td> 
     <td width="10px" vAlign="top">:</td> 
     <td> 

      <table> 
       <tr> 
        <td> 
         <input type="button" value="<spring:message code="dmx.role.form.button.addModule.label"/>" onclick="return addModuleRow();"></input> 
        </td> 
       </tr> 
       <tr><td>&nbsp;</td></tr> 
      </table> 

      <table cellpadding="0" cellspacing="0" border="0" class="tblstyle1" id="moduleTable"> 
       <thead> 
        <tr> 
         <th class="fst" width="200px"> 
          <spring:message code="dmx.role.form.label.moduleName"/> 
         </th> 
         <th width="50px"><spring:message code="dmx.role.form.label.create"/></th> 
         <th width="50px"><spring:message code="dmx.role.form.label.update"/></th> 
         <th width="50px"><spring:message code="dmx.role.form.label.delete"/></th> 
         <th width="30px"></th> 
        </tr> 
       </thead> 
       <tbody id="moduleTBody"> 
        <c:forEach items="${role.modules}" var="module" varStatus="status" > 
         <c:set var="moduleCounter" value="${status.index}"/> 
         <tr id="moduleRowId_${moduleCounter}"> 
          <td class="fst txt-center"> 
           <form:select onchange="checkIfThisModuleAlreadySelected(this);" class="seloption" id="selectedModule_${moduleCounter}" path="modules[${moduleCounter}].id"> 
            <form:option value="" label="-- Select Module --"/> 
            <form:options items="${moduleList}" itemLabel="moduleName" itemValue="id" /> 
           </form:select> 
          </td> 
          <td class="txt-center"> 
           <form:checkbox id="create_${moduleCounter}" path="modules[${moduleCounter}].create"/> 
          </td> 
          <td class="txt-center"> 
           <form:checkbox id="update_${moduleCounter}" path="modules[${moduleCounter}].update"/> 
          </td> 
          <td class="txt-center"> 
           <form:checkbox id="delete_${moduleCounter}" path="modules[${moduleCounter}].delete"/> 
          <td class="txt-center"> 
           <input class="delbtn" id="moduleDelBtn_${moduleCounter}" name="moduleDelBtn[${moduleCounter}]" type="button" onclick="delModuleRow(${moduleCounter});"> 
          </td> 
         </tr> 
        </c:forEach> 
       </tbody>  
      </table>     
     </td> 
    </tr> 
    <tr><td colspan="3" height="3px"></td></tr> 
</table> 

मैं सफलतापूर्वक भूमिका का नाम अर्थात मान्य कर सकते हैं जब भूमिका का नाम खाली मैं एक त्रुटि संदेश मिलता है, लेकिन जब मॉड्यूल चयनित नहीं है मैं किसी भी त्रुटि संदेश नहीं मिलता है।

कृपया मदद

उत्तर

14

अपने मॉड्यूल सूची में @NotNull और @Size की कमी को जोड़ने की मदद करनी चाहिए:

@Valid 
@NotNull 
@Size(min = 1) 
private List<Module> modules; 

@Valid एनोटेशन का कारण बनता है एनोटेट संग्रह के तत्वों मान्य करने की है, लेकिन यह मौसम की पुष्टि नहीं करता है कि संग्रह शून्य नहीं है या इसमें कोई तत्व शामिल है।

संबंधित मुद्दे