Search code examples
javaplayframework-2.0twirlplay-templates

For loop in Play Framework Java


In Play Framework template, I'm trying to iterate between to numbers using for loop.

When I use:

@for(i <- 2010 to 2015)

it works fine. Also, for

@for(i <- 2010 to Constants.CURRENT_YEAR)

it works correctly (gets predefined constant for CURRENT_YEAR from imported class Constants). However, when I try to exchange both numbers with variables

@for(i <- Constants.FIRST_YEAR to Constants.CURRENT_YEAR)

I get an error "value to is not a member of Integer".

Could somebody please tell me what am I doing wrong? I tried putting variables in {} but with no success, and I couldn't find an example with this particular situation.


Solution

  • I create the Constants class :

    public class Constants {
       public static final int MIN = 1;
       public static final int MAX = 10;
    }
    

    And i add the next code in *.scala.html file.

     @for(i <- Constants.MIN to Constants.MAX){
         i
     }
    

    And its good !