[Lift] Re: SessionVars in different snippets
Hello, I dont have to use SessionVars until now, but in near future. But I had the same problem in mind. Is there not a central place to get the user session with all the values stored? I think it is ugly to have sessionVars spread all over my code. with best regards On 5 Jan., 18:13, Naftoli Gugenheim naftoli...@gmail.com wrote: Each SessionVar is distinct. Create one -- it can be global -- and use it in both snippets. - michallchen...@gmail.com wrote: I have two snippets Login and Profile, and I want to read same object stored in session, when I use SessionVar it create two different object: object user extends SessionVar[Box[User]](Empty) // same in two snippets When I set this object in Login.scala : val usr = User.find(By(User.login,login)) user.set(usr) in Profile it's still Empty why? -- You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to lift...@googlegroups.com. To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com. For more options, visit this group athttp://groups.google.com/group/liftweb?hl=en. -- You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to lift...@googlegroups.com. To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/liftweb?hl=en.
Re: [Lift] Re: SessionVars in different snippets
On Wed, Jan 6, 2010 at 8:31 AM, greekscala hellectro...@gmail.com wrote: Hello, I dont have to use SessionVars until now, but in near future. But I had the same problem in mind. Is there not a central place to get the user session with all the values stored? In Java-land you can get/put values into the session. This has all the disadvantages of SessionVars and more. First, your keys (the names of your things) are strewn all over your code, but they are just Strings so if you change a name, you have to look through all your source code for the same String to change the key. This is no different than having the SessionVar declarations all over your code. Second, the get/put mechanism is not type-safe. You can associate anything with a key and when you pull it out, you better hope that both the putter and the getter agree on what the type should be. On the other hand, SessionVars are type safe. Third, with the get/put mechanism, you have to roll your own is the value set? logic (which might be null-based or some other mechanism might be used), where as with SessionVars, you have the lazy creation logic built right into the SessionVar. So, if you'd like to propose a mechanism that somehow centralizes the access to session-related information and doesn't suffer from the above issues, I'm all ears. Thanks, David I think it is ugly to have sessionVars spread all over my code. with best regards On 5 Jan., 18:13, Naftoli Gugenheim naftoli...@gmail.com wrote: Each SessionVar is distinct. Create one -- it can be global -- and use it in both snippets. - michallchen...@gmail.com wrote: I have two snippets Login and Profile, and I want to read same object stored in session, when I use SessionVar it create two different object: object user extends SessionVar[Box[User]](Empty) // same in two snippets When I set this object in Login.scala : val usr = User.find(By(User.login,login)) user.set(usr) in Profile it's still Empty why? -- You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to lift...@googlegroups.com. To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.comliftweb%2bunsubscr...@googlegroups.com . For more options, visit this group athttp:// groups.google.com/group/liftweb?hl=en. -- You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to lift...@googlegroups.com. To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.comliftweb%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/liftweb?hl=en. -- Lift, the simply functional web framework http://liftweb.net Beginning Scala http://www.apress.com/book/view/1430219890 Follow me: http://twitter.com/dpp Surf the harmonics -- You received this message because you are subscribed to the Google Groups "Lift" group. To post to this group, send email to lift...@googlegroups.com. To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/liftweb?hl=en.
[Lift] Re: SessionVars in different snippets
Hello, David I like the SessionVar Idea and the type safety. But as Alex suggests, can I define an object with the fields? I think now when I am writing this I think I understand it more :D I thought it is not possible to have one object that stores the values. But the SessionVar knows what user is requesting a value right? Because SessionVars were always defined inside the snippet class I thought the SessionVar gets the context from the snippet class On 6 Jan., 18:13, Alex Boisvert alex.boisv...@gmail.com wrote: I don't know if it's a common practice but I usually keep all my SessionVars in the same module (aka singleton object) for easy access: /** All session variables */ object Session { private def currentWeekReq = S.param(currentWeek).map(Week.parse(_)) object currentWeek extends SessionVar[Week](currentWeekReq openOr (Week())) { override def is = currentWeekReq openOr super.is } object latestEntry extends SessionVar(latestEntry) object editEntry extends SessionVar(editEntry) object failedEntry extends SessionVar(failedEntry) /* etc... */ } then I just import Session._ wherever needed. alex On Wed, Jan 6, 2010 at 11:31 AM, greekscala hellectro...@gmail.com wrote: Hello, I dont have to use SessionVars until now, but in near future. But I had the same problem in mind. Is there not a central place to get the user session with all the values stored? I think it is ugly to have sessionVars spread all over my code. with best regards On 5 Jan., 18:13, Naftoli Gugenheim naftoli...@gmail.com wrote: Each SessionVar is distinct. Create one -- it can be global -- and use it in both snippets. - michallchen...@gmail.com wrote: I have two snippets Login and Profile, and I want to read same object stored in session, when I use SessionVar it create two different object: object user extends SessionVar[Box[User]](Empty) // same in two snippets When I set this object in Login.scala : val usr = User.find(By(User.login,login)) user.set(usr) in Profile it's still Empty why? -- You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to lift...@googlegroups.com. To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.comliftweb%2bunsubscr...@googlegroups.com . For more options, visit this group athttp:// groups.google.com/group/liftweb?hl=en. -- You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to lift...@googlegroups.com. To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.comliftweb%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/liftweb?hl=en. -- You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to lift...@googlegroups.com. To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/liftweb?hl=en.
Re: [Lift] Re: SessionVars in different snippets
SessionVars have an internal name which is an identifier unique to the SessionVar, not any surrounding context, so you can place the anywhere. -Ross On Jan 6, 2010, at 1:51 PM, greekscala wrote: Hello, David I like the SessionVar Idea and the type safety. But as Alex suggests, can I define an object with the fields? I think now when I am writing this I think I understand it more :D I thought it is not possible to have one object that stores the values. But the SessionVar knows what user is requesting a value right? Because SessionVars were always defined inside the snippet class I thought the SessionVar gets the context from the snippet class On 6 Jan., 18:13, Alex Boisvert alex.boisv...@gmail.com wrote: I don't know if it's a common practice but I usually keep all my SessionVars in the same module (aka singleton object) for easy access: /** All session variables */ object Session { private def currentWeekReq = S.param(currentWeek).map(Week.parse(_)) object currentWeek extends SessionVar[Week](currentWeekReq openOr (Week())) { override def is = currentWeekReq openOr super.is } object latestEntry extends SessionVar(latestEntry) object editEntry extends SessionVar(editEntry) object failedEntry extends SessionVar(failedEntry) /* etc... */ } then I just import Session._ wherever needed. alex On Wed, Jan 6, 2010 at 11:31 AM, greekscala hellectro...@gmail.com wrote: Hello, I dont have to use SessionVars until now, but in near future. But I had the same problem in mind. Is there not a central place to get the user session with all the values stored? I think it is ugly to have sessionVars spread all over my code. with best regards On 5 Jan., 18:13, Naftoli Gugenheim naftoli...@gmail.com wrote: Each SessionVar is distinct. Create one -- it can be global -- and use it in both snippets. - michallchen...@gmail.com wrote: I have two snippets Login and Profile, and I want to read same object stored in session, when I use SessionVar it create two different object: object user extends SessionVar[Box[User]](Empty) // same in two snippets When I set this object in Login.scala : val usr = User.find(By(User.login,login)) user.set(usr) in Profile it's still Empty why? -- You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to lift...@googlegroups.com. To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.comliftweb%2bunsubscr...@googlegroups.com . For more options, visit this group athttp:// groups.google.com/group/liftweb?hl=en. -- You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to lift...@googlegroups.com. To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.comliftweb%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/liftweb?hl=en. -- You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to lift...@googlegroups.com. To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/liftweb?hl=en. -- You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to lift...@googlegroups.com. To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/liftweb?hl=en.
Re: [Lift] Re: SessionVars in different snippets
On Wed, Jan 6, 2010 at 10:51 AM, greekscala hellectro...@gmail.com wrote: Hello, David I like the SessionVar Idea and the type safety. But as Alex suggests, can I define an object with the fields? Sure. I think now when I am writing this I think I understand it more :D I thought it is not possible to have one object that stores the values. But the SessionVar knows what user is requesting a value right? Yes. SessionVar and RequestVar are type-safe front ends to session-scoped or logical request-scoped backing store. Because SessionVars were always defined inside the snippet class I thought the SessionVar gets the context from the snippet class I rarely define my SessionVars inside snippets... I usually make them top-level scope. I like Alex's idiom as well. On 6 Jan., 18:13, Alex Boisvert alex.boisv...@gmail.com wrote: I don't know if it's a common practice but I usually keep all my SessionVars in the same module (aka singleton object) for easy access: /** All session variables */ object Session { private def currentWeekReq = S.param(currentWeek).map(Week.parse(_)) object currentWeek extends SessionVar[Week](currentWeekReq openOr (Week())) { override def is = currentWeekReq openOr super.is } object latestEntry extends SessionVar(latestEntry) object editEntry extends SessionVar(editEntry) object failedEntry extends SessionVar(failedEntry) /* etc... */ } then I just import Session._ wherever needed. alex On Wed, Jan 6, 2010 at 11:31 AM, greekscala hellectro...@gmail.com wrote: Hello, I dont have to use SessionVars until now, but in near future. But I had the same problem in mind. Is there not a central place to get the user session with all the values stored? I think it is ugly to have sessionVars spread all over my code. with best regards On 5 Jan., 18:13, Naftoli Gugenheim naftoli...@gmail.com wrote: Each SessionVar is distinct. Create one -- it can be global -- and use it in both snippets. - michallchen...@gmail.com wrote: I have two snippets Login and Profile, and I want to read same object stored in session, when I use SessionVar it create two different object: object user extends SessionVar[Box[User]](Empty) // same in two snippets When I set this object in Login.scala : val usr = User.find(By(User.login,login)) user.set(usr) in Profile it's still Empty why? -- You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to lift...@googlegroups.com. To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.comliftweb%2bunsubscr...@googlegroups.com liftweb%2bunsubscr...@googlegroups.comliftweb%252bunsubscr...@googlegroups.com . For more options, visit this group athttp:// groups.google.com/group/liftweb?hl=en. -- You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to lift...@googlegroups.com. To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.comliftweb%2bunsubscr...@googlegroups.com liftweb%2bunsubscr...@googlegroups.comliftweb%252bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/liftweb?hl=en. -- You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to lift...@googlegroups.com. To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.comliftweb%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/liftweb?hl=en. -- Lift, the simply functional web framework http://liftweb.net Beginning Scala http://www.apress.com/book/view/1430219890 Follow me: http://twitter.com/dpp Surf the harmonics -- You received this message because you are subscribed to the Google Groups "Lift" group. To post to this group, send email to lift...@googlegroups.com. To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/liftweb?hl=en.
[Lift] Re: SessionVars in different snippets
Everything is alright then :D! with best regards On 6 Jan., 22:00, David Pollak feeder.of.the.be...@gmail.com wrote: On Wed, Jan 6, 2010 at 10:51 AM, greekscala hellectro...@gmail.com wrote: Hello, David I like the SessionVar Idea and the type safety. But as Alex suggests, can I define an object with the fields? Sure. I think now when I am writing this I think I understand it more :D I thought it is not possible to have one object that stores the values. But the SessionVar knows what user is requesting a value right? Yes. SessionVar and RequestVar are type-safe front ends to session-scoped or logical request-scoped backing store. Because SessionVars were always defined inside the snippet class I thought the SessionVar gets the context from the snippet class I rarely define my SessionVars inside snippets... I usually make them top-level scope. I like Alex's idiom as well. On 6 Jan., 18:13, Alex Boisvert alex.boisv...@gmail.com wrote: I don't know if it's a common practice but I usually keep all my SessionVars in the same module (aka singleton object) for easy access: /** All session variables */ object Session { private def currentWeekReq = S.param(currentWeek).map(Week.parse(_)) object currentWeek extends SessionVar[Week](currentWeekReq openOr (Week())) { override def is = currentWeekReq openOr super.is } object latestEntry extends SessionVar(latestEntry) object editEntry extends SessionVar(editEntry) object failedEntry extends SessionVar(failedEntry) /* etc... */ } then I just import Session._ wherever needed. alex On Wed, Jan 6, 2010 at 11:31 AM, greekscala hellectro...@gmail.com wrote: Hello, I dont have to use SessionVars until now, but in near future. But I had the same problem in mind. Is there not a central place to get the user session with all the values stored? I think it is ugly to have sessionVars spread all over my code. with best regards On 5 Jan., 18:13, Naftoli Gugenheim naftoli...@gmail.com wrote: Each SessionVar is distinct. Create one -- it can be global -- and use it in both snippets. - michallchen...@gmail.com wrote: I have two snippets Login and Profile, and I want to read same object stored in session, when I use SessionVar it create two different object: object user extends SessionVar[Box[User]](Empty) // same in two snippets When I set this object in Login.scala : val usr = User.find(By(User.login,login)) user.set(usr) in Profile it's still Empty why? -- You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to lift...@googlegroups.com. To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.comliftweb%2bunsubscr...@googlegroups.com liftweb%2bunsubscr...@googlegroups.comliftweb%252bunsubscr...@googlegroups.com . For more options, visit this group athttp:// groups.google.com/group/liftweb?hl=en. -- You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to lift...@googlegroups.com. To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.comliftweb%2bunsubscr...@googlegroups.com liftweb%2bunsubscr...@googlegroups.comliftweb%252bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/liftweb?hl=en. -- You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to lift...@googlegroups.com. To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.comliftweb%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/liftweb?hl=en. -- Lift, the simply functional web frameworkhttp://liftweb.net Beginning Scalahttp://www.apress.com/book/view/1430219890 Follow me:http://twitter.com/dpp Surf the harmonics -- You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to lift...@googlegroups.com. To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/liftweb?hl=en.