Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to pass nested objects from jsp pages to Spring MVC through jQuery
    text
    copied!<p>I have a form which contains some datafields and I have to pass some corresponding objects to be updated all together in a Spring controller. I'm not achieving to do it due to Spring thrown errors in matter of "Field error in object [parentObject] on field [nestedObject]".</p> <p>For what I imagine that I'm not dealing with these objects correctly. How can I manipulate this objects in order to Spring MVC recognize and manage it properly?</p> <p>Here goes the codes:</p> <p>Corresponding piece of JSP page:</p> <pre><code> &lt;form id="fmActivity" method="post" accept-charset="iso-8859-1,utf-8" novalidate&gt; &lt;div class="fitem"&gt; &lt;label&gt;Description&lt;/label&gt; &lt;textarea id="description" name="description" class="easyui-validatebox" required cols="40" rows="5"&gt; &lt;/textarea&gt; &lt;/div&gt; &lt;div class="fitem"&gt; &lt;label&gt;Comments&lt;/label&gt; &lt;textarea id="comments" name="comments" class="easyui-validatebox" cols="40" rows="5"&gt; &lt;/textarea&gt; &lt;/div&gt; &lt;!-- HERE ARE THE PROBLEMS: PROJECT, EXECUTOR AND DATETIME FIELDS ARE NOT PROCESSED BY SPRING &lt;div class="fitem"&gt; &lt;label&gt;Project (it would be hidden)&lt;/label&gt; &lt;input id="project" type="hidden" name="project" class="easyui-validatebox" required value="${project}"&gt; &lt;/div&gt; &lt;div class="fitem"&gt; &lt;label&gt;Executor (it would be hidden)&lt;/label&gt; &lt;input id="executor" type="hidden" name="executor" class="easyui-validatebox" required value="${executor}"&gt; &lt;/div&gt; &lt;div class="fitem"&gt; &lt;label&gt;Date/Time&lt;/label&gt; &lt;input id="dateTime" class="easyui-datetimebox" required name="dateTime" style="width:150px"&gt; &lt;/div&gt; --&gt; &lt;div class="fitem"&gt; &lt;label&gt;Tag&lt;/label&gt; &lt;input name="tag" class="easyui-validatebox" required&gt; &lt;/div&gt; &lt;input id="button1" name="button1" type="submit" value="submit"&gt; &lt;/form&gt; </code></pre> <p>The JQuery code to process the button click:</p> <pre><code>$('input#button1').click( function() { $.ajax({ url: 'ActivityUpdate', type: 'post', dataType: 'json', data: $('form#fmActivity').serialize(), success: function(data) { alert(data); }, error: function(errobj, str, errt){ alert(str + " " + errt); } }); }); </code></pre> <p>And the MVC Controller:</p> <pre><code>@RequestMapping(value = "/ActivityUpdate") public String update(Activity activity, HttpSession httpSession) { Session sess = (Session) httpSession.getAttribute("hibSess"); ActivityDAO actDao = new ActivityDAO(sess); actDao.persist(activity); return "forward:ActivityList"; } </code></pre> <p>When I try to do the processing without the objects PROJECT, EXECUTOR and the DateTime, it works. Can you help me? Thanks!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload