使用Struts2和jQuery Ajax进行更新功能的问题
此功能的目的在于,用户可以单击多个行和列并进行更改,然后单击更新并在数据库上对其进行更新。
该帖子可以使用Action方法,只需要稍微了解一下如何访问Action类中的brokerDealerFmc和entity变量即可。我想念什么?
谢谢
struts_ajax.xml
<action name="updatemanual" class="com.action.admin.ManualAction" method="updateManualAjax">
<interceptor-ref name="store">
<param name="operationMode">RETRIEVE</param>
</interceptor-ref>
<interceptor-ref name="defaultStack" />
<result type="json">
<param name="noCache">true</param>
<param name="execuleNullProperties">true</param>
<param name="root">jsonData</param>
</result>
</action>
Manual.java
public class ManualImpl extends PersistableImpl implements Manual {
/* Member Variables */
private String brokerDealerFmc;
private String entity;
public String getBrokerDealerFmc() {
return brokerDealerFmc;
}
public void setBrokerDealerFmc(String brokerDealerFmc) {
this.brokerDealerFmc = brokerDealerFmc;
}
public String getEntity() {
return entity;
}
public void setEntity(String entity) {
this.entity = entity;
}
手动操作
private Manual manual = new ManualImpl();
public Manual getManual() {return manual;}
public void setManual(Manual manual) {this.Manual = manual;}
public String updateManualAjax() throws JSONException {
System.out.println(wfsManual.brokerDealerFmc() + " " + wfsManual.entity());
return SUCCESS;
}
manual_update.js
var jsonSaveObject = [];
$('#update').click(function(e) {
saveManual(e, 'Update');
});
function createJSONObject(id, brokerDealer, entity) {
var obj = new Object();
id = id.replace('\n', '\\n');
obj.id = encodeURIComponent(id);
obj.brokerDealerFmc = brokerDealer;
obj.entity = entity;
jsonSaveObject.push(obj);
}
function saveManual(e, action) {
var countRowSelected = 0;
console.log('inside saveManual method ....');
$('#TableManual tbody tr').each(function() {
var result = $(this).children('td').eq(0).children('input[type=checkbox]').eq(0).is(':checked');
if (result) {
++countRowSelected;
e.preventDefault();
var id = $(this).find('td:eq(0)').eq(0).attr('id');
var brokerDealer = $(this).find('td:eq(1)').text();
var entity = $(this).find('td:eq(2)').text();
createJSONObject(id, brokerDealer, entity);
}
});
if (countRowSelected == 0) {
dialogRowSelection();
}
else {
dialogManualUpdateConfirm(action);
}
}
function dialogManualUpdateConfirm() {
$('#dialogManualConfirm').dialog({
title : 'Manual Update',
bgiframe : true,
width : 500,
height : 200,
autoOpen : false,
modal : true,
show : 'fold',
hide : 'blind',
resizable : false,
buttons : {
Yes : function() {
$(this).dialog("close");
var json = new Object();
json.arr = jsonSaveObject;
var jsonString = JSON.stringify(json);
console.log("json string: " + jsonString);
url = 'ajax/updatewfsmanual';
$.ajax({
type: 'POST',
url: url,
data: jsonString,
dataType: "json",
contentType: "application/json; charset-utf-8",
success: function(data) {
console.log(data);
}
});
},
No : function() { $(this).dialog("close"); }
}
});
$('#dialogWFSManualConfirm').dialog("open");
}
json variable 01: {"arr":[{"id":"m4xGaeVup0RSgTo%2BG9dwOA%3D%3D%5Cn","brokerDealerFmc":"Broker Dealer Test","entity":"WFBNA Test"},
{"id":"woTJH2%2Faxf%2Byfc3X23n4og%3D%3D%5Cn","brokerDealerFmc":"Broker Dealer Second","entity":"WFBNA Second"}]}