Foros de discusión

[RESOLVED] Accessing tags from velocity journal templates

thumbnail
Patrik Bergström, modificado hace 15 años.

[RESOLVED] Accessing tags from velocity journal templates

New Member Mensajes: 10 Fecha de incorporación: 14/08/07 Mensajes recientes
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
thumbnail
Patrik Bergström, modificado hace 15 años.

[RESOLVED] RE: Accessing tags from velocity journal templates

New Member Mensajes: 10 Fecha de incorporación: 14/08/07 Mensajes recientes
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.
thumbnail
Artur Linhart, modificado hace 15 años.

RE: [RESOLVED] RE: Accessing tags from velocity journal templates

Expert Mensajes: 459 Fecha de incorporación: 13/09/07 Mensajes recientes
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
thumbnail
Milan Jaroš, modificado hace 15 años.

Service vulnerability

Expert Mensajes: 268 Fecha de incorporación: 18/08/08 Mensajes recientes
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:



#set ($tagsService = $portal.getClass().forName("com.liferay.portlet.tags.service.TagsAssetLocalServiceUtil").getMethod("getService", null).invoke(null, null))
#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.
thumbnail
Sam Bergenstrahle, modificado hace 14 años.

RE: [RESOLVED] RE: Accessing tags from velocity journal templates

New Member Mensajes: 14 Fecha de incorporación: 3/07/09 Mensajes recientes
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!