Friday, May 4, 2012

Access Liferay Service & Util and Custom Portlet Service & Util Class in Velocity Template

Here are the steps to access services and util class of custom portlet in velocity template.

1) Make sure the services and util class which you want to access are available inside tomcat/lib/ext.

2) In order to access services you need to place below property inside portal-ext.


By default this property will be like this


Which means you wont be able to access serviceLocator inside velocity template.
So make sure before you access any service inside velocity template change this


3) Access services using findService Method of Custom Portlet in Velocity.


Normally we use findService(serviceName) method to access Liferay service.
But to access custom portlet service we have to use findService(contextName,ServiceName).

findService(serviceName) will search at the portal level and findService(servletContextName , serviceName) will search at specified portlet level.

4) Access Liferay Services using findService Method in Velocity


5) Access util class using  findUtil Method for inbuilt Util of Liferay


6) Access util Class of Custom Portlet in Velocity refer below link

http://www.liferay.com/web/raymond.auge/blog/-/blogs/2245146

12 comments:

  1. In Liferay Portal 6.2, we enable accessing services in portal-ext.properties using this line of code:

    velocity.engine.restricted.variables=

    I spent several hours to recognize this change.

    ReplyDelete
    Replies
    1. Hello all, i want to call a java method in a velocity code, i found your post about service Locator but i don't understand how to adapt my code in order to call my methode. Could you please help me!

      Thank you in advance.

      Delete
    2. Hi Amit,

      I have tried the access the java class of a portlet from theme as followed by the above step, but still i can't access anything from the java class of portlet. But the above example is working fine with hook, not working with portlet only. Can u please tell me about the problem behind that.

      Delete
  2. This is a nice article here with some useful tips for those who are not used-to comment that frequently. Thanks for this helpful information I agree with all points you have given to us. I will follow all of them.
    best rpa training in bangalore
    rpa training in bangalore
    rpa course in bangalore
    RPA training in bangalore
    rpa training in chennai
    rpa online training

    ReplyDelete
  3. Very nice post here and thanks for it .I always like and such a super contents of these post.Excellent and very cool idea and great content of different kinds of the valuable information's.
    AWS Training in pune
    AWS Online Training
    AWS Training in Bangalore

    ReplyDelete
  4. Thank you so much for the great and very beneficial stuff that you have shared with the world.

    Upgrade your career Learn Mulesoft Training in Bangalore from industry experts get Complete hands-on Training, Interview preparation, and Job Assistance at Softgen Infotech.

    ReplyDelete
  5. Really very happy to say, your post is very interesting to read. I never stop myself to say something about it. You’re doing a great job. Keep it up…

    Became an Expert In Cloud Computing Security Training! Learn from experienced Trainers and get the knowledge to crack a coding interview, @Softgen Infotech Located in BTM Layout.

    ReplyDelete
  6. I'd love to thank you for the efforts you've made in composing this post. I hope the same best work out of you later on too. I wished to thank you with this particular sites! Thank you for sharing. Fantastic sites!
    sap training in chennai

    sap training in tambaram

    azure training in chennai

    azure training in tambaram

    cyber security course in chennai

    cyber security course in tambaram

    ethical hacking course in chennai

    ethical hacking course in tambaram

    ReplyDelete

nRelate Posts Only