Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Mike Perico
Custom Service accessed from Theme
November 27, 2012 7:32 AM
Answer

Mike Perico

Rank: New Member

Posts: 19

Join Date: August 23, 2012

Recent Posts

We have a custom tool that was created (using the steps on Ray's Blog) to work in a template/structure portlet. Everything is working fine and it creating it was straight forward.
We access our custom tool from our portlet in this way:

#set( $navService = $utilLocator.findUtil('nav-service', 'siteService'))

We are then able to make calls to this service and it all works. Now we want to put this same service to work in a theme. I copied the velocity code into it's own vm file and included it in portal_normal.vm. I know the file is corrected getting added to portal_normal.vm, but "navService" is not working. I am assuming that nav-service is not available in the theme context for some reason.

We also followed the wiki here, but it didn't work. It seems the filter is not running correctly even after following these instructions.

We do we need to do to access our custom code in a theme? We also tried using serviceLocator.findService with no luck either.

Any help would be appreciated.
Daniele Baggio
RE: Custom Service accessed from Theme
November 27, 2012 7:46 AM
Answer

Daniele Baggio

Rank: Regular Member

Posts: 237

Join Date: December 5, 2008

Recent Posts

It's better if you access a custom portlet (which use the custom service) from the theme.

Calling custom service from theme is not possible ina direct way, you have to develop an ext enviroment.

bye
David H Nebinger
RE: Custom Service accessed from Theme
November 27, 2012 8:07 AM
Answer

David H Nebinger

Community Moderator

Rank: Liferay Legend

Posts: 11295

Join Date: September 1, 2006

Recent Posts

Mike Perico:
I know the file is corrected getting added to portal_normal.vm, but "navService" is not working. I am assuming that nav-service is not available in the theme context for some reason.


Theme services can only be accessed from the portal context. You have to hook your service in to make it available for the theme to access.
Mike Perico
RE: Custom Service accessed from Theme
November 27, 2012 8:10 AM
Answer

Mike Perico

Rank: New Member

Posts: 19

Join Date: August 23, 2012

Recent Posts

David,

Thanks for the reply, but I am still a bit unsure of your answer means exactly. Can you give an example or post a URL to a wiki page describing what you are saying? I have been researching this all day and I haven't seen anything like what you are describing.

Thank,

Mike
David H Nebinger
RE: Custom Service accessed from Theme
November 27, 2012 9:20 AM
Answer

David H Nebinger

Community Moderator

Rank: Liferay Legend

Posts: 11295

Join Date: September 1, 2006

Recent Posts

I did a wiki page on using Piwik in Liferay. It included a theme change w/ a custom service for piwik. http://www.liferay.com/community/wiki/-/wiki/Main/Adding+Piwik+Web+Analytics+to+Liferay

Basically you need to define your spring xml file that defines your service. Your code implementing the service is deployed as a jar to the global lib directory or as an extra jar deployed in an ext plugin.

Add your spring config file by editing your portal-ext.properties file to include the new file.

This makes the service available in the portal context.

From there your changes at your theme level should see the service using $utilLocator.findUtil().