I have a model class with some methods, most of them are populated using ajax(jquery), I have a model attribute on JSP as orderVo, initially when page loads some values remains blank and when i call different methods they keep on filling using ajax. Now issue is, when 1 method is called after form setup(1st GET) my model attribute is not populating with values.
Part of my JSP is -Code:@Controller @RequestMapping("/order") @SessionAttributes("orderViewVO") public class OrderController { private static final Logger LOGGER = Logger .getLogger(OrderController.class); @Autowired OrderService orderService; //THIS IS THE 1ST METHOD CALLED ON PAGE @RequestMapping(value = "{clientId}", method = RequestMethod.GET) public String showOrderPage(@PathVariable Long clientId, Model model) { model.addAttribute("orderViewVO", new OrderViewVO()); return "/order/orderView"; } //I want model to be updated here @RequestMapping(value = "/pro", method = RequestMethod.POST) public @ResponseBody OrderViewVO fetchProduct( @RequestParam(value = "brId", required = true) String brId, @RequestParam(value = "categoryId", required = true) String categoryId, Model model) { LOGGER.info("Entry fetchProduct()"); LOGGER.debug("Branch Id: " + brId + ", Category Id: " + categoryId); OrderViewVO orderViewVO = null; orderViewVO = orderService.fecthProduct(categoryId, brId); //this has no effects on model values model.addAttribute("orderViewVO", orderViewVO); LOGGER.info("Exit fetchProduct()"); return orderViewVO; } }
orderVo isCode:<script type="text/javascript"> function showOptions(categorySelect,defaultRow) { if(defaultRow=='0') { var categoryId = categorySelect; } else { var categoryId = categorySelect.id; } var brId = document.getElementById("bId").value; $.post("/guru/cloud/order/pro", { brId:brId, categoryId:categoryId, }, function(subMenu){ document.getElementById("tax").value = subMenu.tax; //here i can populate any values fetched in fetchProduct() } showHtml=showHtml+" </table>"; $("#page_content").html(showHtml); }); } </script> <body> <form:form id="orderView" name="orderView" method="post" modelAttribute="orderViewVO" > <jsp:directive.include file="../common/header.jsp" /> <input type="hidden" id="bId" value=""/> <input type="hidden" id="tax" value=""/> <div style="display:none"> <div id="cartCheckoutHiddenDiv"> <!-- cart details to be posted to server --> <form:input path="orderData" type="text" id="orderData" name="orderData" value=""/> <table cellpadding="0" cellspacing="0" width="100%" border="0" class="checkoutTable"> <tr><td colspan="2" style="text-align:center">Order is placed for </td></tr> <!--branchAdd1,branchAdd2 ect are updated in fetchProduct() but are NULL here --> <tr><td style="text-align:center"><form:label path="branchAdd1" /></td> <td><form:label path="branchAdd2" /></td></tr> <tr><td colspan="2">Total Bill amount is : <span id="totalBill"></span></td></tr> <tr><!-- start of info row --> </div> </div> </form:form> </body> </html> </jsp:root>
Can someone please tell me why i am not been able to populate updated orderVo values? Is it because of AJAX? I have even used SessionAttributCode:public class OrderViewVO implements Serializable { private static final long serialVersionUID = 5352956022679804562L; private String branchId = null; private String branchName = null; private String branchAdd1 = null; private String branchAdd2 = null; //getter, setter below


Reply With Quote