Post Map<String,Object> to Spring Controller using Ajax -
i'm trying post model contains map controller, have tried 2 ways:
first i'm using regular tag, reaches controller right string key, object of map gets null
<c:foreach items="${productquote.prodcontm}" var="productquoteobjtm" varstatus="status"> <tr> <td>${productquoteobjtm.key}</td> <td> <input value="${productquoteobjtm.value.qty}" name="prodcontm['${productquoteobjtm.key}']${productquoteobjtm.value}" id="inputquote${status.index}"/> </td> <td>${productquoteobjtm.value.totalprice}</td> </tr> </c:foreach>
also tried pass map using form tag instead, shown in line below:
doesn't reach controller, i'm passing form ajax function:
$(document).ready(function() { $('#quoteform').submit( function(event) { $.ajax({ url : $("#quoteform").attr("action"), data : $("#quoteform").serialize(), type : "post", success : function(response) { $("#prodconfig").html(response); }, error : function(xhr, status, error) { alert("error:"+xhr.responsetext); }}); return false; }); });
this controller expecting model:
@requestmapping(value="/saveconfig",method = requestmethod.post) public modelandview currentquote(@modelattribute("productquote") productquotedto productquote) { .. }
please let me know i'm doing wrong. thanks!
you should use jsp forms instead of raw html forms, make life whole lot simpler.
suppose productquote.prodcontm
map:
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %> <form:form id="quoteform" commandname="productquote"> <c:foreach items="${productquote.prodcontm}" var="entry"> <tr> <td>${entry.key}</td> <td> <form:input path="prodcontm['${entry.key}'].qty" /> </td> <td>${entry.value.totalprice}</td> </tr> </c:foreach> </form:form>
i not if prodcontm['${entry.key}'].qty
in path work.
otherwise, may have adapt map value's dto simple string or primitive
Comments
Post a Comment