Reputation: 93
In JS file, i am invoking an ajax call on click of button which is in jquery dialog. Spring MVC Controller method is invoked which does db entry & creates an object as per it and add in model. The same object properties i use as arguments for spring:message in dialog, but not able to get the object from model. Is there any other way? Note: I need to use message from properties file only.
JSP file
<html>
..
<form:form>
form elements
<div id="dialog-form" class="dialogbox">
<spring:message code="product.createsuccess" arguments="${message.prodCode}, ${message.customerName}, ${message.warehouseName}, ${message.status}"></spring:message>
textbox for entering id & done button code segment
</div>
</form:form>
</html>
Properties file
product.createsuccess = Product {0} created successfully for Customer {1} at {2} in status {3}.
Controller file
public @ResponseBody
String addWarehouseProduct(@PathVariable Long warehouseId, ModelMap model, Principal principal) {
// db operation
model.put("message", createdMessageObjectwithattributes);
return null;
}
segment of Javascript file
..
$( "#dialog-form" ).dialog({
autoOpen: false,
height: 330,
width: 540,
modal: true
});
$('#done').click(function(){
var warehouseId = null;
// warehouseid got from textbox code
if(warehouseId != null) {
var url = $('#contextPath').val() +"/"+ $('#mdmType').val()+ "/addWarehouseProduct/" + warehouseId + "/*.do";
$.ajax({
type: "POST",
url: url,
error: function(e) {
alert('Error: ' + e);
}
});
}
return false;
});
..
Upvotes: 2
Views: 2158
Reputation: 26828
The model is only used when you return a view.
public @ResponseBody String
means that the method returns a simple String, not a view, to the client. Note the @ResponseBody
annotation.
return null;
means that you in fact return nothing. The client gets an empty response.
<spring:message code="product.createsuccess" arguments="${message...
is only evaluated when the page is being rendered. It does not change after the ajax call.
Two easy solutions come to my mind:
Upvotes: 1