我的 SessionVar 对象应该在哪里?
使用 Lift
(Scala
) 进行编程确实压力很大,两者的文档都非常匮乏,而且您能找到的文档也不完整且具有误导性。
好吧,我想做的是将一个简单的字符串存储在 SessionVar
中。因此,一个片段将使用表单填充该字符串的值,而在另一个片段中我将在会话中显示该字符串(或其默认值)。
到目前为止我所拥有的是:
SessionVar
对象:
// the SessionVar will contain a String with "Anonymous" as default value.
object myUser extends SessionVar[String]("Anonymous")
我填充字符串的片段:
object Login extends LiftScreen {
val name = field("Name: ", "")
def finish() {
// set the SessionVar string with the string entered
myUser.set(name)
S.notice("Your name is: "+name)
}
}
我显示字符串的片段(另一个片段):
// show the string in SessionVar
"Your name: " + myUser.is
...
MyUser
是我的对象保存在会话中。最大的问题是:我在哪里保存我的 MyUser
对象?我在 Boot.scala
和两个片段中进行了尝试,但我不断收到此错误:not found: value myUser
。
我应该把它放在哪里?我应该如何导入它?我怎样才能让它发挥作用?
Programming in Lift
(Scala
) is really stressful, both of them have very scarse documentation, and the few you can find is incomplete and misleading.
Well, what I'm trying to do is to store a simple string in a SessionVar
. So, one snippet will fill the value of this string using a form and in another snippet I'm gonna show the string in session (or its default value).
What I have so far is:
The SessionVar
object:
// the SessionVar will contain a String with "Anonymous" as default value.
object myUser extends SessionVar[String]("Anonymous")
Snippet where I fill the string:
object Login extends LiftScreen {
val name = field("Name: ", "")
def finish() {
// set the SessionVar string with the string entered
myUser.set(name)
S.notice("Your name is: "+name)
}
}
Snippet where I show the string (another snippet):
// show the string in SessionVar
"Your name: " + myUser.is
...
MyUser
is the object I'm saving in session. The big question is: where do I keep my MyUser
object? I tried in the Boot.scala
and in the two snippets, but I keep getting this error: not found: value myUser
.
Where should I keep it? How should I import it? How can I make it work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将 SessionVar 放置在与 LiftScreen 相同的“文件”上,但位于对象定义之外。
像这样的事情:
现在,在您的另一个片段上,假设您将其放在不同的文件中(我认为这是因为您正在使用 LiftScreen,但如果您使用的是常规片段类,您可能有多个方法来渲染用户界面。
在另一个文件上,您确实需要导入该对象。
你也可以这样做:
You can place your SessionVar on the same "file" as your LiftScreen, but outside the object definition.
Something like this:
Now, on your other snippet, assuming you have it on a different file (Which I think it is as you are using LiftScreen, but if you were using a regular snippet class you could have more than one method rendering parts of the UI.
On this other file, you do need to import the object.
You can also do it like this: