-
-
Save arvindm1/7099c11ddd9288e8ce46 to your computer and use it in GitHub Desktop.
MVCPortlet for Ajax Call
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ys.foo.portlet; | |
import java.io.IOException; | |
import java.io.PrintWriter; | |
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 { | |
resourceResponse.setContentType("text/javascript"); | |
//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(); | |
writer.write(jsonObject.toString()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment