Erisa
Erisa

Reputation: 61

Play framework 2.0.4 select box sort order

I am currently implementing a UI in play 2.0.4, but I am having problems with the @select helper that I am using for creating a select box. I bind the select to the method Test.methodName which returns a Map object that contains data in the following format:
{2=Sorted1, 1=Sorted2}
As can be seen the data are sorted by their value, and I want this order to be saved when the elements are listed in the select. However, the items are listed in the following order in the select:

Sorted2
Sorted1

It seems like data are sorted by their key. How can I sort by value in the select?

@select(
            paramForm("standardDbName"), 
            options = options(Test.methodName),
            'id -> "standardDb",
            '_default -> "--- Choose DB ---",
            '_label -> "Database Name",
            '_error -> paramForm("standardDbName").error.map(_.withMessage(""))
        )

Upvotes: 1

Views: 399

Answers (2)

Marco
Marco

Reputation: 1493

If are you using java use LinkedHashMap instead of Map.

Upvotes: 2

maxmc
maxmc

Reputation: 4216

The nature of a map is that it's not sorted. You could return a Seq of Tuples Seq("test"-> 1, "test2" -> 2) instead of a map.

Upvotes: 1

Related Questions