简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM