OrderByComparator in Velcoity template

JAOUAD MOUAOU, modified 7 Years ago. New Member Posts: 9 Join Date: 9/27/17 Recent Posts

Hi,

I'm trying to use this method #set ($messages = $MBLocalServiceMessage.getGroupMessages($groupId, 0, -1,-1,  MessageCreateDateComparator  obc)) but I don't know how to use the OrderByComparator method. Thanks

thumbnail
Minhchau Dang, modified 7 Years ago. Liferay Master Posts: 598 Join Date: 10/22/07 Recent Posts
JAOUAD MOUAOU:

Hi,

I'm trying to use this method #set ($messages = $MBLocalServiceMessage.getGroupMessages($groupId, 0, -1,-1,  MessageCreateDateComparator  obc)) but I don't know how to use the OrderByComparator method. Thanks

Have you already using reflection to instantiate the OrderByComparator? It's something that Ray documented in an old blog post, Tricks of Velocity class loading.

JAOUAD MOUAOU, modified 7 Years ago. New Member Posts: 9 Join Date: 9/27/17 Recent Posts

this is what I have done so far but it dosen't seem to work, I want to get messages from Newest to oldests.

#set ($obcClass = $portal.getClass().forName("com.liferay.portlet.messageboards.util.comparator.MessageCreateDateComparator"))
#set ($booleanType = $portal.getClass().forName('java.lang.Boolean'))
#set ($obcConstructor = $obcClass.getConstructor($booleanType.getField('TYPE').staticValue))
#set ($obc = $obcConstructor.newInstance(false))

#set ($messages = $MBLocalServiceMessage.getGroupMessages($groupId, 0, -1, -1, $obc))

JAOUAD MOUAOU, modified 7 Years ago. New Member Posts: 9 Join Date: 9/27/17 Recent Posts

Thank you very much. I've solved the problem by overriding the below parameter. I'm using Liferay 6.2 and it turns out the classes are restricted by default in velocity.

velocity.engine.restricted.classes=