1. 引入js。
参见liferay-portlet.xml
在配置<portlet>时,其中有一项<header-portlet-javascript>
如
<header-portlet-javascript>/html/portlet/mail/packed.js</header-portlet-javascript>
在dtd中这样解释
Set the path of JavaScript that will be referenced in the page's header relative to the portlet's context path.
具体的装载过程在PortletLocalServiceImpl.java中的_readLiferayPortletXML方法中可以看到
2. Ajax方法
var xHR = jQuery.ajax (
{ //定义访问url,对应struts的配置文件
url: themeDisplay.getPathMain() + "/mail/action",
//参数设置
data: {cmd: "getRecipients", data: data.value},
//返回类型
dataType: 'json',
async: false
}
);
3. Action返回josn
在action中通过JSONArray构建json对象返回,具体可参见MailAction.java
Action必须继承JSONAction,覆写父类方法getJSON()
4. 客户端获取并处理
获取返回内容,转化为josn格式
var jsonObj = Liferay.Util.toJSONObject(xmlHttpReq.responseText);