Skip to content
Advertisement

How to maintain accordionPanels in the same order?

I’m using accordionPanel in Primefaces. When I refresh the page the order changes! For example: I have 1,2,3 then they become 2,3,1 or 3,2,1 ! The order of the panels changes everytime I refresh the page!

JavaScript

So I need to know how to fix that, in order to maintain the order of panels in the same way as it is in the html.

Advertisement

Answer

The panels and their ‘order’ come from

JavaScript

Which is not PrimeFaces, nor java-ee, nor java but EL (so the tagging is sort of ‘wrong’). But effectively the EL is a toArray() on an a field of an object. So you could (should) create a simple unit test and see what it does in plain java.

Then with 99.999% certainty you’ll see the order is ‘random’ too, making this question a pure java one. Effectivly the order in Set is not guaranteed as it depends on the implementation (an OrderedSet is, others might not be)

So using an OrderedSet or an (implementation of) Array directly (e.g. an ArrayList) will ‘fix’ this issue

See also

Is a set’s “toArray” deterministic?

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement