Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Patrik Bergström
[RESOLVED] Accessing tags from velocity journal templates
June 23, 2008 9:57 AM
Answer

Patrik Bergström

Rank: New Member

Posts: 10

Join Date: August 14, 2007

Recent Posts

Hi!

I'm wondering if there is any way to access the tags for an article through a velocity journal template? I want to list the tags for an article in the article.

The serviceLocator doesn't seem to be able to access classes like TagsAssetLocalServiceImpl or TagsEntryLocalServiceUtil. Which classes are available to the serviceLocator and which are not?

TIA
Patrik Bergström
[RESOLVED] RE: Accessing tags from velocity journal templates
June 23, 2008 1:51 PM
Answer

Patrik Bergström

Rank: New Member

Posts: 10

Join Date: August 14, 2007

Recent Posts

I managed to solve the issue myself. Here's my solution:

#set ($tagsService = $serviceLocator.findService("com.liferay.portlet.tags.service.TagsAssetLocalService"))
#set ($journalArticleResourceService = $serviceLocator.findService("com.liferay.portlet.journal.service.JournalArticleResourceLocalService"))

#set ($longGroupId = $getterUtil.getLong($groupId))
#set ($articleResourcePK = $journalArticleResourceService.getArticleResourcePrimKey($longGroupId, $reserved-article-id.data))
#set ($tagsAsset = $tagsService.getAsset("com.liferay.portlet.journal.model.JournalArticle", $articleResourcePK))
#set ($tagsEntries = $tagsAsset.getEntries())

Tags:
#foreach( $entry in $tagsEntries )
#set ($tag = $entry.getName())
#if($velocityCount!=1), #end
$tag#end


Edit: The compressed style in the last section is due to the problems with spaces when doing iterations for comma-separated lists like this.
Artur Linhart
RE: [RESOLVED] RE: Accessing tags from velocity journal templates
December 8, 2008 12:18 PM
Answer

Artur Linhart

Rank: Expert

Posts: 458

Join Date: September 13, 2007

Recent Posts

Hello,

this looks great... But in my case (Liferay 5.1.2), the variable $serviceLocator is null and returns nothing if used in article template... Is there any solution for this problem?

cheers, Archie
Milan Jaroš
Service vulnerability
April 8, 2009 5:44 AM
Answer

Milan Jaroš

Rank: Expert

Posts: 269

Join Date: August 18, 2008

Recent Posts

Hello,
as Ray told it can be dangerous to provide serviceLocator in some cases. I can tell you don't be afraid. You can get access to this services without "activating" serviceLocator. We were talking about this with Artur and we've got résumé that it is pretty dangerous to grant access for template modify to untrustworthy people.

The same example as is above but without serviceLocator:


1
2#set ($tagsService = $portal.getClass().forName("com.liferay.portlet.tags.service.TagsAssetLocalServiceUtil").getMethod("getService", null).invoke(null, null))
3#set ($journalArticleResourceService = $portal.getClass().forName("com.liferay.portlet.journal.service.JournalArticleResourceLocalServiceUtil").getMethod("getService", null).invoke(null, null))


I think this should be improved somehow. ;) Maybe with SecurityManager? Don't know.
Sam Bergenstrahle
RE: [RESOLVED] RE: Accessing tags from velocity journal templates
August 12, 2009 12:08 PM
Answer

Sam Bergenstrahle

Rank: New Member

Posts: 14

Join Date: July 3, 2009

Recent Posts

I just wanted to say Thank You!
Your sharing this info made my day. And how refreshing it is to see not only a good question, but also a very good answer in these forums!

Stay well my friends!