1
在JS文件中,我在jQuery對話框中單擊按鈕時調用ajax調用。 Spring MVC Controller方法被調用,它的db條目&按照它創建一個對象並添加到模型中。我用作spring的參數的相同對象屬性:對話框中的消息,但無法從模型中獲取對象。有沒有其他方法? 注:我只需要使用屬性文件中的消息。在jQuery對話框中完成ajax調用之後需要使用模型屬性
JSP文件
<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>
屬性文件
product.createsuccess = Product {0} created successfully for Customer {1} at {2} in status {3}.
控制器的文件的Javascript
public @ResponseBody
String addWarehouseProduct(@PathVariable Long warehouseId, ModelMap model, Principal principal) {
// db operation
model.put("message", createdMessageObjectwithattributes);
return null;
}
段文件
..
$("#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;
});
..
我不能實現的第一個選項,因爲消息需要在道具文件中。你能詳細解釋一下實現第二個選項嗎,我只想重新加載對話框來反映新的模型屬性變化,但正如你所說的,模型只能在視圖返回時使用。 – Soheb
您創建一個只包含對話框代碼的jsp,並像普通頁面一樣返回視圖。 – zeroflagL
感謝您的答案@zeroflagL – Soheb