मेरे पास दो मॉडल एट्रिब्यूट्स वाला एक फॉर्म है, एक नागरिक है और दूसरा सजा है। दो ऑब्जेक्ट्स jquery टैब से अलग होते हैं। मुझे फॉर्म पर आइटम ठीक से प्रदर्शित करने में समस्याएं आ रही हैं कुछ प्रदर्शित किए जा रहे हैं और कुछ नहीं हैं। मेरा मतलब एचटीएमएल तत्व है।उसी फॉर्म पर स्प्रिंग एमवीसी एकाधिक मॉडल एट्रिब्यूट
मुझे यकीन नहीं है कि पेज पर एकाधिक मॉडेल एट्रिब्यूट होने पर नियंत्रक कैसा दिखाई देगा। के तहत कोड का एक नमूना है:
पृष्ठ
<title>Citizen Registration</title>
</head>
<body>
<div id="tabs">
<ul>
<li><a href="#tab1">Citizen Registration</a></li>
<li><a href="#tab2">Punishment</a></li>
</ul>
<div id="tab1">
<form:form id="citizenRegistration" name ="citizenRegistration" method="post" modelAttribute="citizens" action="citizen_registration.htm">
<div id="divRight" class="mainDiv">
<div class="divGroup" id="divCharInfo">
<fieldset>
<legend>Characteristics Info</legend>
<ol>
<li><form:label for="photo" path="photo">Select Photo</form:label>
<form:input path="photo" type="file" id="photo" title="Upload a photo"/><form:errors path="photo" id="errors"/></li>
<li>
<label>Select Gender</label>
<form:select path="genderId" id="genderId" title="Select Your Gender">
<form:options items = "${gender.genderList}" itemValue="genderId" itemLabel="genderDesc" />
</form:select>
<form:errors path="genderId" class="errors"/>
</li>
<li><form:label for="weight" path="weight">Enter Weight <i>(lbs)</i></form:label>
<form:input path="weight" id="weight" title="Enter Weight"/><form:errors path="weight" id="errors"/>
</li>
<li><form:label for="height" path="height">Enter Height <i>(feet)</i></form:label>
<form:input path="height" id="height" title="Enter Height"/><form:errors path="height" id="errors"/>
</li>
.......................
<div id="tab2">
<form:form id="punishmentRegistration" name ="punishmentRegistration" method="post" modelAttribute="punishment" action="punishment_registration.htm">
<ol>
<li>
<form:label for ="punishmentId" path="punishmentId">Punishment Number</form:label>
<form:input path="punishmentId" id="punishmentId"/><form:errors path="punishmentId" id="errors"/>
</li>
<li>
<form:label for="crimeRecNo" path="crimeRecNo">Select Crime</form:label>
<form:select path="crimeRecNo" id="CrimeRecNo" title="Select Crime">
<form:options items = "${crime.crimeList}" itemValue="crimeRecNo" itemLabel="crimeRecNo" title="crimeDesc"/>
</form:select>
<form:errors path="crimeRecNo" id="errors"/>
</li>
<li>
<form:label for ="monitoringStDate" path="monitoringStDate"> Start Date </form:label>
<form:input path="monitoringStDate" id="monitoringStDate"/><form:errors path="monitoringStDate" id="errors"/>
</li>
<li>
<form:label for ="monitoringEnDate" path="monitoringEnDate"> End Date </form:label>
<form:input path="monitoringEnDate" id="monitoringEnDate"/><form:errors path="monitoringEnDate" id="errors"/>
</li>
</ol>
</form:form>
</div>
</div>
</body>
</html>
नियंत्रक
@RequestMapping(value="citizen_registration.htm", method = RequestMethod.GET)
public ModelAndView loadPage(HttpServletRequest request,
HttpServletResponse response,
@ModelAttribute Citizens citizens, @ModelAttribute Punishment punishment,
BindingResult result,
ModelMap m, Model model) throws Exception {
//code here
return new ModelAndView("citizen_registration");
यह मेरा कोड लेकिन जब मैं इसे tab2 में कुछ भी नहीं प्रदर्शित किया जाता है andnot में सभी तत्वों को चलाया जाता है टैब 1 दिखाया गया है।
क्या आप एक कक्षा बनाते हैं जो इन दो वर्गों का संदर्भ देता है जो काम करेगा? – devdar
ठीक है अगर आप मानक वसंत रूपों के साथ जाना चाहते हैं। फिर कई मॉडलों को बांधने के लिए आप मॉडल युक्त एक फॉर्म क्लास बना सकते हैं। लेकिन मैंने वसंत बाध्यकारी रूप को आसान पाया क्योंकि वे एक अतिरिक्त कक्षा को लागू करने की आवश्यकता को हटा देते हैं। इसके अलावा, प्रत्येक मॉडल के लिए सत्यापन अलग से किया जा सकता है। इसके अलावा, यह नेस्टेड मॉडल को बांधने की कार्यक्षमता भी प्रदान करता है। –
मैं समझता हूं कि आप क्या कह रहे हैं कि आप केवल अलग-अलग रूपों का उपयोग करने की सिफारिश करेंगे? – devdar