Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
andres digiovanni
velocity template get assetEntry
February 26, 2013 1:54 AM
Answer

andres digiovanni

Rank: New Member

Posts: 14

Join Date: September 18, 2012

Recent Posts

Hi!

I'm developping a web content template. I'm trying to get the ID of a AssetEntry but I can't get the attributs.


My code is :
1#set ($assetEntryLocalService = $serviceLocator.findService("com.liferay.portlet.asset.service.AssetEntryLocalService"))
2#set ($assetEntry = $assetEntryLocalService.getEntry("com.liferay.portlet.journal.model.JournalArticle", $resourceprimKey))
3
4$assetEntry



When I print $assetEntry I get:
1
2{entryId=11731, groupId=10528, companyId=10154, userId=10196, userName=Test Test, createDate=Fri Feb 15 09:16:17 GMT 2013, modifiedDate=Thu Feb 21 10:47:54 GMT 2013, classNameId=10108, classPK=11729, classUuid=0b9aeff3-63b8-4ac6-9db3-fa7dfafbbd70, classTypeId=11703, visible=true, startDate=null, endDate=null, publishDate=Fri Feb 15 09:15:00 GMT 2013, expirationDate=null, mimeType=text/html, title=, description=, summary=, url=, layoutUuid=, height=0, width=0, priority=0.0, viewCount=432}


This is a table row.

How can I get the entryId's value? I try to use the functions getEntryId(), split(","), ...... But doesn't work!

Edit: I'm using liferay 6.1.1

If anyone knows how to solve this problem I be gratefull.

Thanks!
Andrew
Juhi Kumari
RE: velocity template get assetEntry
February 26, 2013 2:20 AM
Answer

Juhi Kumari

Rank: Expert

Posts: 346

Join Date: December 12, 2011

Recent Posts

Hi,

Your $resourceprimKey is 0 so you are not getting $assetEntry.
I set value for $resourceprimKey then its wirking fine.
BTW from where you are getting $resourceprimKey ???

Regards
Juhi
andres digiovanni
RE: velocity template get assetEntry
February 26, 2013 2:26 AM
Answer

andres digiovanni

Rank: New Member

Posts: 14

Join Date: September 18, 2012

Recent Posts

Hi,

I put all the code:

 1#set ($groupId = $themeDisplay.getLayout().getGroupId())
 2
 3#set ($journalArticleLocalService = $serviceLocator.findService("com.liferay.portlet.journal.service.JournalArticleLocalService"))
 4#set ($ja = $journalArticleLocalService.getArticle( $groupId, $reserved-article-id.data ))
 5#set ($resourceprimKey = $ja.getResourcePrimKey())
 6
 7#set ($assetEntryLocalService = $serviceLocator.findService("com.liferay.portlet.asset.service.AssetEntryLocalService"))
 8#set ($assetEntry = $assetEntryLocalService.getEntry("com.liferay.portlet.journal.model.JournalArticle", $resourceprimKey))
 9
10$assetEntry



The $resourceprimKey is diferent to 0. It has the correct value.

$assetEntry has the values I need but I can't access in it.


Regards,
Andrew
Juhi Kumari
RE: velocity template get assetEntry
February 26, 2013 3:45 AM
Answer

Juhi Kumari

Rank: Expert

Posts: 346

Join Date: December 12, 2011

Recent Posts

Hi,
Replace your 4th line with this
1#set ($ja = $journalArticleLocalService.getArticle($getterUtil.getLong($groupId),$getterUtil.getString($reserved-article-id.data)))

Now it will work.

Regards
Juhi
James Falkner
RE: velocity template get assetEntry
February 26, 2013 6:40 AM
Answer

James Falkner

LIFERAY STAFF

Rank: Liferay Legend

Posts: 1197

Join Date: September 17, 2010

Recent Posts

andres digiovanni:


$assetEntry has the values I need but I can't access in it.


You should be able to call $assetEntry.getEntryId() - if that does not work then something has gone horribly wrong emoticon Also, make sure you uncheck 'cacheable' when editing the template.
andres digiovanni
RE: velocity template get assetEntry
February 26, 2013 8:52 AM
Answer

andres digiovanni

Rank: New Member

Posts: 14

Join Date: September 18, 2012

Recent Posts

I tried to use the methods getEntryId() but doesn't work. I don't know what has gone wrong.

I try your solution Juhi Kumari, but doesn't work.

Anyone has gone a similar error?

Thank you for the answers!
Andrew
Juhi Kumari
RE: velocity template get assetEntry
February 26, 2013 9:19 PM
Answer

Juhi Kumari

Rank: Expert

Posts: 346

Join Date: December 12, 2011

Recent Posts

Hi,

Did you put this line in your portal-ext.properties ???
1journal.template.velocity.restricted.variables=


Regards
Juhi
Devendra Patel
RE: velocity template get assetEntry
February 26, 2013 10:04 PM
Answer

Devendra Patel

Rank: Junior Member

Posts: 71

Join Date: September 25, 2011

Recent Posts

Hi,

Do you want to get entryID?

If yes then you can achieve it by string split operation.$assetEntry is a String.so you can write like

#set ($arrayTemp = $assetEntry.split("entryId="))
#set($entryID = $arrayTemp[1].split(",")[0])

Hope this help you.

Regards,

Dev Patel
andres digiovanni
RE: velocity template get assetEntry
February 27, 2013 9:32 AM
Answer

andres digiovanni

Rank: New Member

Posts: 14

Join Date: September 18, 2012

Recent Posts

Hi!

It works!

I modified the portal-ext.properties.

Juhi Kumari:
Hi,

Did you put this line in your portal-ext.properties ???
1journal.template.velocity.restricted.variables=


Regards
Juhi



I had this:

1journal.template.velocity.restricted.variables=true


And I replaced it for:

1journal.template.velocity.restricted.variables=



I don't understand why the others methods works fine.

Thanks everybody for the answers!!

Regards,
Andrew
Devendra Patel
Re: [Liferay Forums][3. Development] RE: velocity template get assetEntry
February 28, 2013 10:11 PM
Answer

Devendra Patel

Rank: Junior Member

Posts: 71

Join Date: September 25, 2011

Recent Posts

Hi,

Do you want to get entryID?

If yes then you can achieve it by string split operation.$assetEntry is a
String.so you can write like

#set ($arrayTemp = $assetEntry.split("entryId="))
#set($entryID = $arrayTemp[1].split(",")[0])

Hope this help you.

Regards,

Dev Patel
Devendra Patel
Re: [Liferay Forums][3. Development] RE: velocity template get assetEntry
February 28, 2013 10:11 PM
Answer

Devendra Patel

Rank: Junior Member

Posts: 71

Join Date: September 25, 2011

Recent Posts

Hi,

Do you want to get entryID?

If yes then you can achieve it by string split operation.$assetEntry is a
String.so you can write like

#set ($arrayTemp = $assetEntry.split("entryId="))
#set($entryID = $arrayTemp[1].split(",")[0])

Hope this help you.

Regards,

Dev Patel
Devendra Patel
Re: [Liferay Forums][3. Development] RE: velocity template get assetEntry
February 28, 2013 10:11 PM
Answer

Devendra Patel

Rank: Junior Member

Posts: 71

Join Date: September 25, 2011

Recent Posts

Hi,

Do you want to get entryID?

If yes then you can achieve it by string split operation.$assetEntry is a
String.so you can write like

#set ($arrayTemp = $assetEntry.split("entryId="))
#set($entryID = $arrayTemp[1].split(",")[0])

Hope this help you.

Regards,

Dev Patel
Devendra Patel
Re: [Liferay Forums][3. Development] RE: velocity template get assetEntry
February 28, 2013 10:11 PM
Answer

Devendra Patel

Rank: Junior Member

Posts: 71

Join Date: September 25, 2011

Recent Posts

Hi,

Do you want to get entryID?

If yes then you can achieve it by string split operation.$assetEntry is a
String.so you can write like

#set ($arrayTemp = $assetEntry.split("entryId="))
#set($entryID = $arrayTemp[1].split(",")[0])

Hope this help you.

Regards,

Dev Patel
Devendra Patel
Re: [Liferay Forums][3. Development] RE: velocity template get assetEntry
February 28, 2013 10:11 PM
Answer

Devendra Patel

Rank: Junior Member

Posts: 71

Join Date: September 25, 2011

Recent Posts

Hi,

Do you want to get entryID?

If yes then you can achieve it by string split operation.$assetEntry is a
String.so you can write like

#set ($arrayTemp = $assetEntry.split("entryId="))
#set($entryID = $arrayTemp[1].split(",")[0])

Hope this help you.

Regards,

Dev Patel
Pravin Pawar
RE: velocity template get assetEntry
April 10, 2013 4:46 AM
Answer

Pravin Pawar

Rank: Junior Member

Posts: 62

Join Date: November 17, 2009

Recent Posts

James,

$assetEntry.getEntryId(). It's working fine