Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
petar tahchiev
Velocity arrays
March 30, 2012 1:39 AM
Answer

petar tahchiev

Rank: New Member

Posts: 3

Join Date: March 13, 2012

Recent Posts

Hi guys,

I am building a custom template with a custom navigation (velocity file). My navigation will show the latest publiched articles in a given category. It all works great with just one tiny problem.
This is the code to create my query:
1
2#set ($arr = ['$category.getCategoryId()'])
3$assetEntryQuery.setStart(0)
4$assetEntryQuery.setEnd(6)
5$assetEntryQuery.setAllCategoryIds($arr)
6$assetEntryQuery.setClassName($classNameLocalServiceUtil.getClassName(10108).getValue())
7#set ($entries = $assetEntryService.getEntries($assetEntryQuery))


as you can see the method $assetEntryQuery.setAllCategoryIds($arr) accepts a parameter that is an array of category id's. I can't make it to work because the $arr is velocity array and not a Java array. When displaying the navigation I can see this line printed on the page:

1
2$assetEntryQuery.setAllCategoryIds($arr)


and the navigation shows all the articles in all the categories.

Do you know how to pass the velocity array to the method?

Thanks, Petar.
petar tahchiev
RE: Velocity arrays
March 31, 2012 1:28 PM
Answer

petar tahchiev

Rank: New Member

Posts: 3

Join Date: March 13, 2012

Recent Posts

Come on guys... this is a typical Velocity question emoticon someone must know it?!
Amos Fong
RE: Velocity arrays
April 2, 2012 2:29 AM
Answer

Amos Fong

LIFERAY STAFF

Rank: Liferay Legend

Posts: 1898

Join Date: October 7, 2008

Recent Posts

Hi Petar,

I think you would need some rather complex reflection to create a long array, however, in your case there's an easy way to get a long array by other means emoticon. Try this:

1#set ($arr = $assetEntryQuery.getAllCategoryIds())
2#set ($arr = $arrayUtil.append($arr, $category.getCategoryId()))
Tapas Ranjan Patra
RE: Velocity arrays
September 3, 2012 1:14 AM
Answer

Tapas Ranjan Patra

Rank: New Member

Posts: 19

Join Date: December 22, 2010

Recent Posts

Hi All,

I tried below code to pass single categoryId to create assetEntryQuery but it is not working. Please help me on this.

#set ($arr = [$getterUtil.getLong($forthChild.getData())])
#set ($arr = $arrayUtil.append($arr, $getterUtil.getLongValues($getterUtil.getLong($forthChild.getData()))))
#set ($assetEntryQuery = $assetEntryQuery.setAllCategoryIds($arr))

Thanks & Regards,
Tapas