掲示板

How to create portlet with JSON response

7年前 に David Knol によって更新されました。

How to create portlet with JSON response

Junior Member 投稿: 29 参加年月日: 15/06/19 最新の投稿
Hi,
I am trying to create portlet, which after invoking returns JSON with data from database. What I'm tryintg to do is pretty similar to GetLayoutsAction class, which extends JSONAction. Can you guide me step by step what should I do? I have created new MVCPortlet so far. What should I do next? I'm fresh with Liferay.
thumbnail
7年前 に David H Nebinger によって更新されました。

RE: How to create portlet with JSON response

Liferay Legend 投稿: 14918 参加年月日: 06/09/02 最新の投稿
You can return json using the serveResource() method in the portlet, but I'd suggest going the service builder route so you can leverage the whole /api/jsonws entry point rather than trying to do within a portlet.
7年前 に David Knol によって更新されました。

RE: How to create portlet with JSON response

Junior Member 投稿: 29 参加年月日: 15/06/19 最新の投稿
Ok, thank you. Another thing. I've genereted a new MVCPortlet using Blade, so I have something like that:

package example.portlet;

@Component(
	immediate = true,
	property = {
		"com.liferay.portlet.display-category=category.sample",
		"com.liferay.portlet.instanceable=true",
		"javax.portlet.display-name=Example Portlet",
		"javax.portlet.init-param.template-path=/",
		"javax.portlet.init-param.view-template=/view.jsp",
		"javax.portlet.resource-bundle=content.Language",
		"javax.portlet.security-role-ref=power-user,user"
	},
	service = Portlet.class
)
public class ExamplePortlet extends MVCPortlet {

	@Override
	public void serveResource(ResourceRequest request, ResourceResponse response) throws IOException, PortletException {
		...
	}
	
}


What I'd like to do is to call this portlet from existing JS file using A.io.request and process received JSON. What will be URL of that resource? Is there something more I should do to make it works?