Plugin portlet Custom JSON Services

Plugin portlet Custom JSON Services:
1) Create Service.xml for you required Entity.
2) Run ant build-service
3) Run build-wsdd
4) Write required method in EntityServiceImpl.
5) Please check this method signature will created in EntityServiceUtil
6) Call the following URL to Access the custom method and this will return JSON array or JSON object.
7) http://127.0.0.1:8080/JSONTest-portlet/json/?serviceClassName=com.meera.test.service.SongServiceUtil&serviceMethodName=getSongObject&serviceParameters=[songId]&songId=2



Note: 127.0.0.1 this is your host Name
JSONTest-portlet this is context path of your portlet.


The Following is Example:
Plugin Portlet Name: JSONTest-portlet
Service.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE service-builder PUBLIC "-//Liferay//DTD Service Builder 6.0.0//EN" "http://www.liferay.com/dtd/liferay-service-builder_6_0_0.dtd">
<service-builder package-path="com.meera.test">
<author>meera</author>
<namespace>meera</namespace>

<entity name="Song" local-service="true" remote-service="true">
<!-- PK fields -->
<column name="songId" type="long" primary="true" />
<!-- Audit fields -->
<column name="songName" type="String" />
<column name="songDesc" type="String" />
</entity>
</service-builder>



Method Name: getSongObject(long songId)

package com.meera.test.service.impl;
public class SongServiceImpl extends SongServiceBaseImpl {
public Song getSongObject(long songId) throws SystemException{
return SongUtil.fetchByPrimaryKey(songId);

}
}
}


Note: above method auto generate method after run service builder.
Write this Java script in view.jsp
<script src="/html/js/jquery/jquery.js" language="javascript"type="text/javascript"></script>

<script>
function getjsonParentObject(){
jQuery.ajax({
url : http://127.0.0.1:8080/JSONTest-portlet/json/?serviceClassName=com.meera.test.service.SongServiceUtil&serviceMethodName=getSongObject&serviceParameters=[songId]&songId=2',
dataType : "json",
success:function(msg) {
alert("====="+msg.songId);
},
error : function() {

}
}); 
}
</script>

Share on Google Plus

About Meera Prince

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment