我想存储会话变量,然后用它来修改菜单中Boot.scala。这里是我正在存储在代码段中变量:

object sessionUserType extends  SessionVar[String](null)
  def list (xhtml : NodeSeq) : NodeSeq = {

    Helpers.bind("sendTo", xhtml, 
                 "provider" -> SHtml.link("/providerlogin",() => sessionUserType("provider"), Text("Provider")),
                 "student" -> SHtml.link("/studentlogin",() => sessionUserType("student"), Text("Student")))
    }

然后,在Boot.scala我这样做:

val studentSessionType = If(() => S.getSessionAttribute("sessionUserType").open_!.equals("student"),
            "not a student session") 

我也试图调用由名称(sessionUserType)的对象,但它永远无法找到它,所以我想这可能工作,但我不断收到一个空框,当我访问它,即使实际的约束力和功能得到执行之前的菜单渲染。

任何帮助,将不胜感激。

由于

有帮助吗?

解决方案

为了获得从SessionVarRequestVar一个值,调用is方法就可以了,即sessionUserType.is

顺便说一句,你读 “治国”<? / p>

边注

我相信RequestVar你的情况更适合。我不知道我能赶上你的代码不正确的背景下,但它至少可以像被改写:

case class LoginType
case object StudentLogin extends LoginType
case object ProviderLogin extends LoginType

object loginType extends RequestVar[Box[LoginType]](Empty)
// RequestVar is a storage with request-level scope

...
"provider" -> SHtml.link("/providerlogin",() => loginType(Full(ProviderLogin)), Text("Provider")),
// `SHtml.link` works in this way. Your closure will be called after a user
// transition, that is when /providerlogin is loading.
...

val studentSessionType = If(() => { loginType.is map {_ == StudentLogin} openOr false },
                "not a student session")
// As a result, this test will be true if our RequestVar holds StudentLogin,
// but it will be so for one page only (/studentlogin I guess). If you want
// scope to be session-wide, use SessionVar

其他提示

我想断开是,你假设一个的会话属性的是要符合您的 SessionVar 的,这是不是这样的。电梯是一个非常安全框架,以及一个,如果其功能是提升创建不透明的GUID指上的组件 服务器端。

如果你想getSessionAttribute返回的东西,想想你能怎么称呼setSessionAttribute

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top