Vista combinada Visión Plana Vista de árbol
Discusiones [ Anterior | Siguiente ]
Patrik Bergström
[RESOLVED] Accessing tags from velocity journal templates
23 de junio de 2008 9:57
Respuesta

Patrik Bergström

Ranking: New Member

Mensajes: 10

Fecha de incorporación: 14 de agosto de 2007

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
Patrik Bergström
[RESOLVED] RE: Accessing tags from velocity journal templates
23 de junio de 2008 13:51
Respuesta

Patrik Bergström

Ranking: New Member

Mensajes: 10

Fecha de incorporación: 14 de agosto de 2007

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.
Artur Linhart
RE: [RESOLVED] RE: Accessing tags from velocity journal templates
8 de diciembre de 2008 12:18
Respuesta

Artur Linhart

Ranking: Expert

Mensajes: 458

Fecha de incorporación: 13 de septiembre de 2007

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
Milan Jaroš
Service vulnerability
8 de abril de 2009 5:44
Respuesta

Milan Jaroš

Ranking: Expert

Mensajes: 269

Fecha de incorporación: 18 de agosto de 2008

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:


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
12 de agosto de 2009 12:08
Respuesta

Sam Bergenstrahle

Ranking: New Member

Mensajes: 14

Fecha de incorporación: 3 de julio de 2009

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!