当前位置: 代码迷 >> Web前端 >> UI 直连通过Jquery调用action
  详细解决方案

UI 直连通过Jquery调用action

热度:138   发布时间:2012-08-30 09:55:54.0
UI 直接通过Jquery调用action
1, JS code:
$(document).ready(function(){
$('#paymentSO\\.debitAccountSO\\.no').change(function() {
var cashAccountId = document.getElementById("paymentSO.debitAccountSO.no");

if(!cashAccountId){
return;
}
//post方法参数解析:
//"domesticPayment-entry.do?method=doPopulateDefaultFee":所调用的action
//$("#DomesticPaymentForm").serialize():参数传递载体(action from)。
//function(obj):obj-aciont返回的对象。
if(cashAccountId.value != ""){
$.post("domesticPayment-entry.do?method=doPopulateDefaultFee", $("#DomesticPaymentForm").serialize(), function(obj){
var arr = obj.split(",");
document.getElementById("paymentSO.feeAmount").value = arr[0];
document.getElementById("feeCcy").innerHTML = arr[1];
document.getElementById("hiddenFeeCcy").value = arr[1];
});
}
});
});

2,后台代码:
public ActionForward doPopulateDefaultFee(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response) {
try {
defaultFeeExtension.setDefaultFee(form);
} catch (CashAccountServiceException e) {
if(LOG.isErrorEnabled()){
LOG.error("Cash Account Service errors ", e);
}
}
String feeAmt = defaultFeeExtension.getDefaultFee();
PaymentForm paymentForm = (PaymentForm) form;
String feeAmtCcy = paymentForm.getPaymentSO().getFeeCurrency();
StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append(feeAmt).append(",").append(feeAmtCcy);
try {
response.getWriter().print(stringBuffer);
} catch (IOException e) {
LOG.error("doPopulateDefaultFee ", e);
}
return null;
}


  相关解决方案