Skip to content

Instantly share code, notes, and snippets.

@arvindm1 arvindm1/ Secret
Created Nov 14, 2011

What would you like to do?
MVCPortlet for Ajax Call
import java.util.ArrayList;
import javax.portlet.PortletException;
import javax.portlet.ResourceRequest;
import javax.portlet.ResourceResponse;
import com.liferay.portal.kernel.json.JSONFactoryUtil;
import com.liferay.portal.kernel.json.JSONObject;
import com.liferay.util.bridges.mvc.MVCPortlet;
* Portlet implementation class
public class MyMVCPortlet extends MVCPortlet {
public void serveResource(ResourceRequest resourceRequest, ResourceResponse resourceResponse)
throws PortletException, IOException {
//Print What you get from Server
System.out.println("param1 sent from Browser- " + resourceRequest.getParameter("param1"));
System.out.println("param2 sent from Browser- " + resourceRequest.getParameter("param2"));
JSONObject jsonObject = JSONFactoryUtil.createJSONObject();
ArrayList<String> strList = new ArrayList<String>();
strList.add("FIRST ONE");
strList.add("SECOND ONE");
//Send Data Back
jsonObject.put("retVal1", "Returing First value from server");
jsonObject.put("retVal2", strList.toString());
PrintWriter writer = resourceResponse.getWriter();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.