Foren

Get new instance in Volecity template

jason zhao, geändert vor 8 Jahren.

Get new instance in Volecity template

New Member Beiträge: 7 Beitrittsdatum: 05.08.14 Neueste Beiträge
I've been trying to get a instance of Collections in vm template for Gallery display template.
I write
#set($coll = $portal.getClass().forName("java.util.Collections").newInstance())
    $coll.shuffle($entries)

this in my template.
I think it should work, but I got $coll.shuffle($entries) this displayed on my actual page.
I'm not sure what's wrong, help me plz.
thumbnail
James Falkner, geändert vor 8 Jahren.

RE: Get new instance in Volecity template

Liferay Legend Beiträge: 1399 Beitrittsdatum: 17.09.10 Neueste Beiträge
See this thread. The Collections class cannot be instantiated (no public constructors) and consists only of static utility methods.
jason zhao, geändert vor 8 Jahren.

RE: Get new instance in Volecity template

New Member Beiträge: 7 Beitrittsdatum: 05.08.14 Neueste Beiträge
Thx for replying. I tried this before, there's no error but the list didn't seem to be shuffled at all no matter how many times I refresh the page or clean the VM and database cache.
#set ($coll = $portal.getClass().forName('java.util.Collections'))
    #set ($V = $coll.shuffle($entries))
    #foreach ($curFileEntry in $entries)


Is there someting wrong with the way I code?
thumbnail
James Falkner, geändert vor 8 Jahren.

RE: Get new instance in Volecity template

Liferay Legend Beiträge: 1399 Beitrittsdatum: 17.09.10 Neueste Beiträge
This worked for me in 6.2:

#set ($coll = $portal.getClass().forName('java.util.Collections'))

#if (!$entries.isEmpty())
    #set ($V = $coll.shuffle($entries))

    <ul>
	#foreach ($curEntry in $entries)
		<li>$curEntry.getTitle($locale)</li>
	#end
	</ul>
#end


Every time I refresh the page, the order of article titles is changed randomly.
jason zhao, geändert vor 8 Jahren.

RE: Get new instance in Volecity template

New Member Beiträge: 7 Beitrittsdatum: 05.08.14 Neueste Beiträge
Thx for answering, I tried this exact code in my Liferay 6.2 EE, didn't work...Maybe there's a patch or sth?
thumbnail
James Falkner, geändert vor 8 Jahren.

RE: Get new instance in Volecity template

Liferay Legend Beiträge: 1399 Beitrittsdatum: 17.09.10 Neueste Beiträge
Which version of 6.2 EE, and which version of Java are you using? I'll get the exact same setup and try it.