I am using token input to search data as follows:
<portlet:resourceURL var="categoryRequestURL" />
<script type="text/javascript">
$(document).ready(function () {
var catUrl = "<%=categoryRequestURL%>";
var cat_input_id = "<%=portletNamespace%>categories_selector";
$("#textbox_id").tokenInput(catUrl, {theme: "facebook"});
});
</script>
And in the public void serveResource():
PrintWriter writer = resourceResponse.getWriter();
JSONObject j1 = JSONFactoryUtil.createJSONObject();
j1.put("id", "1");
j1.put("name", "Data center");
JSONObject j2 = JSONFactoryUtil.createJSONObject();
j2.put("id", "2");
j2.put("name", "Database");
catJsonArray.put(j1);
catJsonArray.put(j2);
writer.write(jsonArray.toString().trim());
writer.flush();
writer.close();
The problem was whatever I entered in the input box, all data in the json array was displayed:
However, if I hard coded json data instead of using resource url. Then it worked correctly. Does any one have any ideas?
I have no experience with liferay in the slightest, but think I can see what is 'theoretically' the problem.
With jquery tokeninput, when you use an external URL to get your search results, you must deal with the search logic yourself. This is to allow you to query databases and such like. The search parameter is (by default) sent to your page in the GET parameter 'q', and the JSON you return should only be the relevant search results, rather than the entire collection of data.
As I say, I have no idea how to implement such a thing using liferay - but from looking at your code, there doesn't seem to be any point where that logic could be in there!