mkayad
mkayad

Reputation: 61

Play framework 2 tag compilation error

I am new to Play framework 2 and I am trying to implement a simple tag supported by a Java class. But I can not get working because I am getting a compilation error

compilation error on the browser illegal start of simple expression In \app\views\tags\security.scala.html at line 3.

tag file views/tags/security.scala.html

@(roles:String)(body:Html)
@import helpers.SecurityHelper._
@if(restricted (@session().get("roles"),@roles)==true){
@body
}

Helper class code package helpers;

public class SecurityHelper {
    public static boolean restricted(String userRoles, String ressourceRoles) {
        String[] roles = userRoles.split("_");
        boolean b = false;
        for (int i = 0; i < roles.length; i++) {
            if (roles[i].indexOf(ressourceRoles) != -1) {
                b = true;
            }
        }
        return b;
    }
}

how I want to use it: in my other template, I call the tag as follow:

@security("job-view"){
Welcome
}

I can't figure out the problem, any suggestion? Thanks

Upvotes: 0

Views: 190

Answers (1)

magmel
magmel

Reputation: 600

maybe you need write next first line of html-file:

@(roles:String, body:Html)(implicit session: Session)

and not "@session" in if-statement, "session" enough

but I need more information about errors

Upvotes: 1

Related Questions