在Lift Scala中存储会话变量
发布时间:2020-12-16 08:55:23 所属栏目:安全 来源:网络整理
导读:我试图存储一个会话变量,然后用它来修改Boot. scala中的菜单.以下是我将变量存储在代码段中的方法: object sessionUserType extends SessionVar[String](null) def list (xhtml : NodeSeq) : NodeSeq = { Helpers.bind("sendTo",xhtml,"provider" - SHtml.l
我试图存储一个会话变量,然后用它来修改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),但它永远找不到它,所以我认为这可能有用,但是当我访问它时我仍然得到一个空盒子,即使实际的绑定和函数在执行之前执行菜单渲染. 任何帮助将非常感激. 谢谢 解决方法
为了从SessionVar或RequestVar获取值,请在其上调用方法,即sessionUserType.is
顺便问一下,你读过“Managing State”吗? 边注 我相信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)),// `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 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
热点阅读