0

I want to use @helper.select form Play 2 template engine where I should specify Seq[(String,String)] containing data for <options>. But I have List<Enum>. And I know rather weakly Scala.

Without this helper I populate <select> using this code:

@for( category <- Categories.values()){
   <option value="@category">@Messages.get( category.getI18NName )</option>
}

And definition of Category:

public enum Category{
    CATEGORY1{
        @Override
        public String getI18NName(){
            return "category.category1";
        }
    },
    CATEGORY2{
        @Override
        public String getI18NName(){
            return "category.category2";
        }
    };

    public String getI18NName(){
        return null;
    }
}

For test I used options = options("1" -> "1", "2" -> "2", "3" -> "3", "4" -> "4", "5" -> "5") form Java example of inputRadioGroup in Play2

How can I get Seq[(String,String)] from my List<Enum>?

Thanks

Community
  • 1
  • 1
nickotinus
  • 323
  • 5
  • 17

1 Answers1

2

You can use a for comprehension here:

for (c <- Category.values()) yield c.name() -> c.getI18NName()

This will return an Array[(String, String)] but scala will handle conversion when the expected type is Seq[(String, String)].

yakshaver
  • 2,472
  • 1
  • 18
  • 21