Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Tuomas Katva
Using Liferay APIs from Portlet
June 25, 2012 2:49 AM
Answer

Tuomas Katva

Rank: New Member

Posts: 8

Join Date: September 26, 2010

Recent Posts

Hi

I am new with Portlet and Liferay development, but I was wondering is it possible to access Liferay APIs from portlet (for example User, Organization, etc...) ? Especially from Vaadin portlet. First test that I would like to do is just get the logged users name and print it to the Vaadin portlet.

If someone could point me to right direction it would be greatly appreciated. Examples, tutorials would be really great.

Thank you

Best Regards Tuomas
Sandeep Nair
RE: Using Liferay APIs from Portlet
June 25, 2012 3:58 AM
Answer

Sandeep Nair

Rank: Liferay Legend

Posts: 1692

Join Date: November 5, 2008

Recent Posts

Hi,

You can definitely use Liferay APIs within a portlet.
Like to get the information of a user who is logged in i normally use PortalUtil.getUser(request)

I havent worked with Vaadin portlet, but I dont see why you cannot use Liferay API's

Regards,
Sandeep
David H Nebinger
RE: Using Liferay APIs from Portlet
June 25, 2012 4:43 AM
Answer

David H Nebinger

Rank: Liferay Legend

Posts: 6520

Join Date: September 1, 2006

Recent Posts

Tuomas Katva:
I am new with Portlet and Liferay development, but I was wondering is it possible to access Liferay APIs from portlet (for example User, Organization, etc...) ?


Of course you can use the APIs from a portlet. They're designed to work from portlet plugins. All you need to do is identify the entity you want to access, then use the XxxLocalServiceUtil class to retrieve them.

Especially from Vaadin portlet.


We're doing all of our business portlets in Vaadin now, and we use the APIs all the time.

First test that I would like to do is just get the logged users name and print it to the Vaadin portlet.


Ah, now this one does not require the API (since the user is available using better methods).

For this one, you want to make your Vaadin application class implement the PortletRequestHolder interface. This will add two methods to your application, onRequestStart() and onRequestEnd(). We use a ThreadLocal to store the passed PortletRequest so it is available to the Vaadin portlet.

In order to get the the User, your ThreadLocal instance with the PortletRequest object just needs to call the PortalUtil.getUser(portletRequest) method call.

Note: The one issue you're going to face is that there are no containers defined that map to the Liferay API list returns (Vaadin has data containers that map to result sets, so you can create tables for scrolling over the data returned from a query; there are no associated containers that can leverage the Liferay API's abilities to scroll over the result sets). Not so much of a big deal, but you have to manage your scrolling yourself...
Tuomas Katva
RE: Using Liferay APIs from Portlet
June 25, 2012 4:50 AM
Answer

Tuomas Katva

Rank: New Member

Posts: 8

Join Date: September 26, 2010

Recent Posts

Thank you for quick answers... emoticon This is really great. Where do I find these Util-class jars? Do I just download SDK and reference these from there ?


Thank you very much.
Hitoshi Ozawa
RE: Using Liferay APIs from Portlet
June 25, 2012 5:06 AM
Answer

Hitoshi Ozawa

Rank: Liferay Legend

Posts: 7990

Join Date: March 23, 2010

Recent Posts

Check the online liferay documentation on setting up development environment.
http://www.liferay.com/documentation/liferay-portal/6.1/development
David H Nebinger
RE: Using Liferay APIs from Portlet
June 25, 2012 5:54 AM
Answer

David H Nebinger

Rank: Liferay Legend

Posts: 6520

Join Date: September 1, 2006

Recent Posts

They are part of portal-service.jar and are available to you automagically, you don't have to do anything to pull them into a project.
Hitoshi Ozawa
RE: Using Liferay APIs from Portlet
June 30, 2012 7:43 AM
Answer

Hitoshi Ozawa

Rank: Liferay Legend

Posts: 7990

Join Date: March 23, 2010

Recent Posts

Yes David but if he's developing a portlet, he should be downloading Liferay SDK and setting it up. :-)

BTW, I also recommend using Liferay IDE. Liferay IDE can be downloaded from Liferay's download page.