dw和java,dwr2与struts2整合

本文详细介绍了如何将Direct Web Remoting (DWR) 框架与Struts2进行整合,主要涉及DWRActionUtil.js的修改,用于执行远程请求,并提供了回调函数的实现。该文章适合于需要在Struts2应用中使用DWR进行异步交互的开发者阅读。
摘要由CSDN通过智能技术生成

# re: dwr2与struts2整合

2009-01-03 21:53 | 肖亮亮

经过一般研究,修改修改

DWRActionUtil.js里报错,stactk overflow at line 28

DWRActionUtil.js的内容

/*

* Copyright 2005 Joe Walker / Alexandru Popescu

*

* Licensed under the Apache License, Version 2.0 (the "License");

* you may not use this file except in compliance with the License.

* You may obtain a copy of the License at

*

* http://www.apache.org/licenses/LICENSE-2.0

*

* Unless required by applicable law or agreed to in writing, software

* distributed under the License is distributed on an "AS IS" BASIS,

* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

* See the License for the specific language governing permissions and

* limitations under the License.

*/

/**

* Declare an object to which we can add real functions.

*/

if (dwr == null) var dwr = {};

if (dwr.struts2 == null) dwr.struts2 = {};

if (DWRActionUtil == null) var DWRActionUtil = dwr.struts2;

/** Execute a remote request using DWR */

dwr.struts2.execute = function(action, values, callbackObjOrName) {

var params = {};

if (dwr.struts2.isElement(values)) {

var element = $(values);

var elementName= element.nodeName.toLowerCase();

if (elementName == 'form') {

for (var i = 0; i < element.elements.length; i=i+1) {

var e = element.elements[i];

if (e.name != null && e.name != '') params[e.name] = dwr.util.getValue(e);

}

}

else {

params[element.name] = dwr.util.getValue(element);

}

}

else {

for (var prop in values) {

params[prop]= values[prop];

}

}

// prepare action invocation object

var actionObj = {};

if (typeof action == 'string') {

var lastIdx= action.lastIndexOf('/');

actionObj.executeResult = 'true';

if (lastIdx != -1) {

actionObj.namespace = action.substring(0, lastIdx);

actionObj.action = action.substring(lastIdx + 1);

}

else {

actionObj.namespace= '';

actionObj.action = action;

}

}

else {

actionObj= action;

}

// prepare the DWR callback object

var callbackObj = {};

var mustCall= false;

if (typeof callbackObjOrName == 'string') {

callbackObj.callback = function(dt) { dwr.struts2.callback(dt, eval(callbackObjOrName)); };

mustCall= true;

}

else if (typeof callbackObjOrName == 'function') {

callbackObj.callback = function(dt) { dwr.struts2.callback(dt, callbackObjOrName); };

mustCall= true;

}

else if (typeof callbackObjOrName == 'object' && typeof callbackObjOrName.callback == 'function') {

for (var prop in callbackObjOrName) {

callbackObj[prop] = callbackObjOrName[prop];

}

callbackObj.callback = function(dt) { dwr.struts2.callback(dt, callbackObjOrName.callback); };

mustCall= true;

}

if (mustCall) {

dwr.struts2.execute(actionObj, params, callbackObj);

}

};

/** Execute a remote request using DWR */

dwr.struts2.callback = function(dt, originalCallback) {

if (dt.data) originalCallback(dt.data);

else if (dt.text) originalCallback(dt.text);

else originalCallback(dt);

};

/** Utility to check to see if the passed object is an input element / element id */

dwr.struts2.isElement = function(elementOrId) {

if (typeof elementOrId == "string") {

return true;

}

if (elementOrId.nodeName) {

var name= elementOrId.nodeName.toLowerCase();

if (name == 'input' || name == 'form') {

return true;

}

}

return false;

};

回复  更多评论

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值