Total Pageviews

Monday, February 28, 2011

Calling remote service method using Javascript/JSON

Liferay enables us to call the methods using Javascript. There are various advantages of it, but the most useful is - we can call a method without refreshing a the portlet (without rendering), and we can display contents as per logic.



Step 1. Firstly, generate your service for your entity keeping remote-service="true"  in service.xml

Step 2. Write a method in ServiceImpl that you wish to call from Javascript.

Step 3. Build service using ant, from ext-impl.

Step 4. Deploy the whole project.

e.g. 
Step 5. Method will be available in ext-web/docroot/html/js/liferay/ext_service.js.

Step 6. Include js in the jsp file you need to call the method, as follows:

<script type="text/javascript" src="/html/js/liferay/ext_service.js"></script>
Step 7. Call method as follows in javascript:




This is it... All the best...

4 comments:

  1. Just wonder if you have any example of calling into a server method with Java object parameters rather than primitive type?

    E.g. your lifeIt() method on the server takes has this signature:

    likeIt(Token token, String postId)

    Where Token is just a user defined Java object?

    Thanks.

    ReplyDelete
  2. Can we access the same in custom portlet developed in plugins sdk(LR 5.2.x)

    ReplyDelete
  3. hi Your providing nice and useful information to us thankful to you
    Learn salesforce online training by real time expert with real time scenarios and in-depth explanation of the subject. Salesforce makes
    revolutionary business applications, cloud servers, generation of leads, faster deals, selling, servicing and marketing smarter. Through Salesforce Online Training you are also able to learn Salesforce CRM Development, Salesforce Classroom training, Administration and Salesforce.com Integration modules with different concepts by each and every module.

    salesforce online training

    ReplyDelete