zipWithIndex makes looping in Scala fun

December 23rd, 2017 | #scala #playframework

TIL how to use zipWithIndex in Scala.

@for((element, index) <- list.zipWithIndex) {
    <p>index @index is element @element</p>
}
Read more

Passing Default group to form(...) in Play 2.6.x when using group constraints in forms

November 17th, 2017 | #java #playframework

TIL if you pass custom groups to the form(...) method in Play 2.6.x, you also have to pass the group javax.validation.groups.Default explicitly—if you want any of its fields taken into account during the validation process of a form.

Form<FooForm> form = formFactory().form(FooForm.class, Default.class, FooCheck.class).bindFromRequest();
Read more

Use Scala match expression in Play Scala template

November 6th, 2017 | #scala #playframework #html

TIL how to use Scala match expression in a Play Scala template.

@badgeColor(subscription: String) = {
    @subscription match {
        case "Authorised" => { primary }
        case "Pending" => { secondary }
        case "Confirmed" | "Paid out" => { success }
        case "Failed" | "Cancelled" => { danger }
        case "Expired" => { warning }
        case "Charged back" => { info }
        case _ => { @* applies also if "Open" *@ light }
    }
}
Read more

Keep track of datetime an entity was last modified with Ebean in Play

October 31st, 2017 | #ebean #playframework #java #sql

TIL that Ebean helps you to keep track of the datetime an entity was last modified. I wanted to implement a column last_modified_at, when a colleague showed me this commit. You simply can add a timestamp property to a model with the annotation @WhenModified. Ebean will set the timestamp to the datetime when the entitiy was last modified.

Read more

© 2018 Tonny Garić | With from Nijmegen, The Netherlands