liferay的autocompletelist输入框动态提示

由于项目需要如同百度一样的边输入边获取后台数据进行提示的功能。所以考虑使用jquery的autocomeplete组件。但是由于不知道为什么。请求的时候 extraParams就是不生效。用firebug看 根本请求时候没带这个参数。所以考虑改用liferay的aui.aui的解决方案如下。

1.页面端

 

 <%@page import="com.liferay.portal.kernel.util.Constants"%>
<%@ include file="init.jsp"%>
<liferay-portlet:resourceURL var="autoComURL">
</liferay-portlet:resourceURL>
<portlet:resourceURL var="getUsers">
       <portlet:param name="<%=Constants.CMD%>" value="get_users" />
</portlet:resourceURL>
<h2>Liferay Auto Complete List with Ajax</h2><br/>
<aui:input id="myInputNode" name="myInputNode" label="User Email"
       helpMessage="Type User Email address in Input Box" />
<aui:script>
AUI().use('autocomplete-list','aui-base','aui-io-request','autocomplete-filters','autocomplete', 'autocomplete-highlighters', function (A) {
	A.one('body').addClass('yui3-skin-sam');
	A.one('#<portlet:namespace />myInputNode').plug(A.Plugin.AutoComplete, {
		source: function (query, callback) {
			var inputValue=A.one("#<portlet:namespace />myInputNode").get('value');
			var myAjaxRequest=A.io.request('<%=getUsers%>',{
				dataType: 'json',
				method:'POST',
				data:{
					<portlet:namespace/>keywords:inputValue,
				},
				autoLoad:false,
				sync:false,
				on: {
				success:function(){
					var data=this.get('responseData');
					var a1 = eval(data);
					callback(a1);
				}}
			});
			myAjaxRequest.start();
		}
	});
});
</aui:script>

而在后台代码中 则这么写

@Override
	public void serveResource(ResourceRequest resourceRequest,
			ResourceResponse resourceResponse) throws IOException,
			PortletException {
		String email= ParamUtil.getString(resourceRequest, "email");
		System.out.println(email);
		String result = "[a,b,c,d]";
		PrintWriter out = resourceResponse.getWriter();
		out.println(result);
		super.serveResource(resourceRequest, resourceResponse);
	}