[英]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. 我是Play框架2的新手,我正在尝试实现Java类支持的简单标签。 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. 浏览器上的编译错误非法开始的简单表达式在\\ app \\ views \\ tags \\ security.scala.html中的第3行。
tag file views/tags/security.scala.html 标记文件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: 也许您需要编写html文件的下第一行:
@(roles:String, body:Html)(implicit session: Session)
and not "@session" in if-statement, "session" enough 而不是if语句中的“ @session”,足够“ session”
but I need more information about errors 但我需要更多有关错误的信息
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.