【问题标题】:Play framework 2 tag compilation error播放框架2标签编译错误
【发布时间】:2013-05-11 16:55:11
【问题描述】:

我是 Play 框架 2 的新手,我正在尝试实现一个 Java 类支持的简单标记。 但我无法开始工作,因为我遇到了编译错误

浏览器编译错误 简单表达式的非法开头 在第 3 行的 \app\views\tags\security.scala.html 中。

标签文件 视图/标签/security.scala.html

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

助手类代码 包助手;

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;
    }
}

我想如何使用它: 在我的另一个模板中,我将标签称为如下:

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

我无法解决问题,有什么建议吗? 谢谢

【问题讨论】:

    标签: frameworks tags playframework-2.0 helper


    【解决方案1】:

    也许你需要写下 html 文件的第一行:

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

    而不是 if 语句中的“@session”,“会话”就足够了

    但我需要有关错误的更多信息

    【讨论】:

      猜你喜欢
      • 2015-08-14
      • 1970-01-01
      • 1970-01-01
      • 2017-08-22
      • 1970-01-01
      • 2013-01-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多