Fórumok
[RESOLVED] Accessing tags from velocity journal templates
Patrik Bergström, módosítva 15 év-val korábban
[RESOLVED] Accessing tags from velocity journal templates
New Member Bejegyzések: 10 Csatlakozás dátuma: 2007.08.14. Legújabb bejegyzések
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
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, módosítva 15 év-val korábban
[RESOLVED] RE: Accessing tags from velocity journal templates
New Member Bejegyzések: 10 Csatlakozás dátuma: 2007.08.14. Legújabb bejegyzések
I managed to solve the issue myself. Here's my solution:
Edit: The compressed style in the last section is due to the problems with spaces when doing iterations for comma-separated lists like this.
#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, módosítva 15 év-val korábban
RE: [RESOLVED] RE: Accessing tags from velocity journal templates
Expert Bejegyzések: 459 Csatlakozás dátuma: 2007.09.13. Legújabb bejegyzések
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
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š, módosítva 15 év-val korábban
Service vulnerability
Expert Bejegyzések: 268 Csatlakozás dátuma: 2008.08.18. Legújabb bejegyzések
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:
I think this should be improved somehow. ;) Maybe with SecurityManager? Don't know.
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.
Sam Bergenstrahle, módosítva 14 év-val korábban
RE: [RESOLVED] RE: Accessing tags from velocity journal templates
New Member Bejegyzések: 14 Csatlakozás dátuma: 2009.07.03. Legújabb bejegyzések
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!
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!