[Lift] Re: how to add object into session scope in lift
David Pollak wrote: On Thu, Apr 30, 2009 at 10:48 PM, Andrew Scherpbier and...@scherpbier.org mailto:and...@scherpbier.org wrote: The Getting Started document got me hooked on Lift. :-) I guess I'll report my struggles from there. I don't know if what I did is typical. After actually running the two examples from the Getting Started docs, I looked and found some other examples, did some looking around in the mailing list archives and started reading the Exploring Lift book. As a starting application of lift, I want to write a simple purchase order tracking webapp. It was easy enough to figure out how to hook up PostgreSQL instead of Derby. I started experimenting with the CRUDify trait and got several tables working, but then I got stuck trying to make a more cohesive app. What I could not figure out was how to use CRUDify's functionality without having to put all the options in the SiteMap. So I spent a lot of time trying to figure out the SiteMap class. I have since come to the realization that I probably shouldn't be using CRUDify, as non of the examples actually use it. I have also realized that I should be putting rules in LiftRules.rewrite. I don't think so. I think that you should be using SiteMap. SiteMap is the best tool for defining site navigation and access control rules around. CRUDify and ProtoUser are like scaffolding... they get you some pieces really quickly, but you'll ultimately need to replace them. You should never have to replace SiteMap. So... what's the specific challenge you're running into with SiteMap? The first challenge I had was trying to figure out how to keep the functionality of CRUDify, but not the menu items. The docs state that you can override defs. ie: *createMenuLoc* |def createMenuLoc| The menu item for listing items (make this Empty to disable) Box javascript:void[Menu javascript:void] But I don't want to disable it, just hide it from the menu. Then, failing that, I wanted to put the menu items in a sub-menu in the SiteMap. I wasn't able to accomplish this while keeping the CRUDify functionality functioning. (The submenu seems to always to add a level to URI but the CRUDify trait doesn't know about that? I could be grossly wrong, of course!) Ultimately, in the app I'm trying to build, CRUDify would only be useful for the main record type. Most other records have a 1-n relationship with the main record. It is unclear to me how to use CRUDify in this situation. (I can use CRUDify to add a PO, but how do I use CRUDify to add SKUs to a specific PO?) So, looking at the pocketchange app which has this kind of record relationship as well, I figured that CRUDify was not the right solution. (I hope I'm wrong, because I like what CRUDify provides!) So, my point, I guess, is that it was never clear to me what request rewriting was all about. I didn't understand the explanations and basically just skipped it and tried to do everything with SiteMap. What I have taken away from this: Request Rewriting sounds very advanced and made me think of sendmail rewriting rules! (Yuck!) Maybe it would be good to have some blurbs on Lift for JEE developers. What is the equivalent of mapping a URL to a servlet and how do you deal with the URL pattern matching. (I want to map /foo/* to a some soft of action) So that would then be a nice lead-in to coverage of net.liftweb.http.S, right? Anyway, back to API docs, it never occurred to be to look at the docs for net.liftweb.http.LiftRules! There are actually lots of comments there. The rewrite is kinda hidden there, so it probably should be called out in the class docs. Then for the actual rewrite docs, it would be nice to give some examples of what should go in there or provide a link to external docs showing the same. How have other people tackled the learning curve of lift? --Andrew Derek Chen-Becker wrote: In terms of the API docs part of it would just be expanding on the current scaladoc to provider better explanation. Obviously there are a ton of classes to document, so I'd like to focus efforts on getting the most bang for the buck. I was thinking of starting with net.liftweb.http.{LiftRules,S,SHtml} and making the documentation on them *outstanding*. We can branch out from there. If you're coming to Lift new, it would also be helpful to find out what we're missing or need to cover better in the Getting Started document on the web site. If you want to read through that and provide feedback here on the list that would be great. Derek On Thu, Apr 30, 2009 at 12:20 PM, Andrew Scherpbier and...@scherpbier.org mailto:and...@scherpbier.org
[Lift] Re: how to add object into session scope in lift
On Sat, May 2, 2009 at 12:35 PM, Andrew Scherpbier and...@scherpbier.orgwrote: David Pollak wrote: On Thu, Apr 30, 2009 at 10:48 PM, Andrew Scherpbier and...@scherpbier.org mailto:and...@scherpbier.org wrote: The Getting Started document got me hooked on Lift. :-) I guess I'll report my struggles from there. I don't know if what I did is typical. After actually running the two examples from the Getting Started docs, I looked and found some other examples, did some looking around in the mailing list archives and started reading the Exploring Lift book. As a starting application of lift, I want to write a simple purchase order tracking webapp. It was easy enough to figure out how to hook up PostgreSQL instead of Derby. I started experimenting with the CRUDify trait and got several tables working, but then I got stuck trying to make a more cohesive app. What I could not figure out was how to use CRUDify's functionality without having to put all the options in the SiteMap. So I spent a lot of time trying to figure out the SiteMap class. I have since come to the realization that I probably shouldn't be using CRUDify, as non of the examples actually use it. I have also realized that I should be putting rules in LiftRules.rewrite. I don't think so. I think that you should be using SiteMap. SiteMap is the best tool for defining site navigation and access control rules around. CRUDify and ProtoUser are like scaffolding... they get you some pieces really quickly, but you'll ultimately need to replace them. You should never have to replace SiteMap. So... what's the specific challenge you're running into with SiteMap? The first challenge I had was trying to figure out how to keep the functionality of CRUDify, but not the menu items. The docs state that you can override defs. ie: *createMenuLoc* |def createMenuLoc| The menu item for listing items (make this Empty to disable) Box javascript:void[Menu javascript:void] But I don't want to disable it, just hide it from the menu. Then, failing that, I wanted to put the menu items in a sub-menu in the SiteMap. I wasn't able to accomplish this while keeping the CRUDify functionality functioning. (The submenu seems to always to add a level to URI but the CRUDify trait doesn't know about that? I could be grossly wrong, of course!) Super-menus and sub-menus share no URL information with each other. A super-menu could be at /foo/bar/baz/super and sub-menus could be at /dog and /cat Ultimately, in the app I'm trying to build, CRUDify would only be useful for the main record type. Most other records have a 1-n relationship with the main record. It is unclear to me how to use CRUDify in this situation. (I can use CRUDify to add a PO, but how do I use CRUDify to add SKUs to a specific PO?) CRUDify is for building simple CRUD apps. It's not meant for complex relationships. Until someone comes up with something better, you'll have to hand-code the relationships and the screens for the relationships. So, looking at the pocketchange app which has this kind of record relationship as well, I figured that CRUDify was not the right solution. (I hope I'm wrong, because I like what CRUDify provides!) Sorry. David So, my point, I guess, is that it was never clear to me what request rewriting was all about. I didn't understand the explanations and basically just skipped it and tried to do everything with SiteMap. What I have taken away from this: Request Rewriting sounds very advanced and made me think of sendmail rewriting rules! (Yuck!) Maybe it would be good to have some blurbs on Lift for JEE developers. What is the equivalent of mapping a URL to a servlet and how do you deal with the URL pattern matching. (I want to map /foo/* to a some soft of action) So that would then be a nice lead-in to coverage of net.liftweb.http.S, right? Anyway, back to API docs, it never occurred to be to look at the docs for net.liftweb.http.LiftRules! There are actually lots of comments there. The rewrite is kinda hidden there, so it probably should be called out in the class docs. Then for the actual rewrite docs, it would be nice to give some examples of what should go in there or provide a link to external docs showing the same. How have other people tackled the learning curve of lift? --Andrew Derek Chen-Becker wrote: In terms of the API docs part of it would just be expanding on the current scaladoc to provider better explanation. Obviously there are a ton of classes to document, so I'd like to focus efforts on getting the most bang for the buck. I was thinking of starting with
[Lift] Re: how to add object into session scope in lift
On Thu, Apr 30, 2009 at 10:48 PM, Andrew Scherpbier and...@scherpbier.orgwrote: The Getting Started document got me hooked on Lift. :-) I guess I'll report my struggles from there. I don't know if what I did is typical. After actually running the two examples from the Getting Started docs, I looked and found some other examples, did some looking around in the mailing list archives and started reading the Exploring Lift book. As a starting application of lift, I want to write a simple purchase order tracking webapp. It was easy enough to figure out how to hook up PostgreSQL instead of Derby. I started experimenting with the CRUDify trait and got several tables working, but then I got stuck trying to make a more cohesive app. What I could not figure out was how to use CRUDify's functionality without having to put all the options in the SiteMap. So I spent a lot of time trying to figure out the SiteMap class. I have since come to the realization that I probably shouldn't be using CRUDify, as non of the examples actually use it. I have also realized that I should be putting rules in LiftRules.rewrite. I don't think so. I think that you should be using SiteMap. SiteMap is the best tool for defining site navigation and access control rules around. CRUDify and ProtoUser are like scaffolding... they get you some pieces really quickly, but you'll ultimately need to replace them. You should never have to replace SiteMap. So... what's the specific challenge you're running into with SiteMap? So, my point, I guess, is that it was never clear to me what request rewriting was all about. I didn't understand the explanations and basically just skipped it and tried to do everything with SiteMap. What I have taken away from this: Request Rewriting sounds very advanced and made me think of sendmail rewriting rules! (Yuck!) Maybe it would be good to have some blurbs on Lift for JEE developers. What is the equivalent of mapping a URL to a servlet and how do you deal with the URL pattern matching. (I want to map /foo/* to a some soft of action) So that would then be a nice lead-in to coverage of net.liftweb.http.S, right? Anyway, back to API docs, it never occurred to be to look at the docs for net.liftweb.http.LiftRules! There are actually lots of comments there. The rewrite is kinda hidden there, so it probably should be called out in the class docs. Then for the actual rewrite docs, it would be nice to give some examples of what should go in there or provide a link to external docs showing the same. How have other people tackled the learning curve of lift? --Andrew Derek Chen-Becker wrote: In terms of the API docs part of it would just be expanding on the current scaladoc to provider better explanation. Obviously there are a ton of classes to document, so I'd like to focus efforts on getting the most bang for the buck. I was thinking of starting with net.liftweb.http.{LiftRules,S,SHtml} and making the documentation on them *outstanding*. We can branch out from there. If you're coming to Lift new, it would also be helpful to find out what we're missing or need to cover better in the Getting Started document on the web site. If you want to read through that and provide feedback here on the list that would be great. Derek On Thu, Apr 30, 2009 at 12:20 PM, Andrew Scherpbier and...@scherpbier.org mailto:and...@scherpbier.org wrote: Derek, That's awesome. I want to help. What can I do? I can start by proof reading stuff. --Andrew -- Lift, the simply functional web framework http://liftweb.net Beginning Scala http://www.apress.com/book/view/1430219890 Follow me: http://twitter.com/dpp Git some: http://github.com/dpp --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to liftweb@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: how to add object into session scope in lift
The Getting Started document got me hooked on Lift. :-) I guess I'll report my struggles from there. I don't know if what I did is typical. After actually running the two examples from the Getting Started docs, I looked and found some other examples, did some looking around in the mailing list archives and started reading the Exploring Lift book. As a starting application of lift, I want to write a simple purchase order tracking webapp. It was easy enough to figure out how to hook up PostgreSQL instead of Derby. I started experimenting with the CRUDify trait and got several tables working, but then I got stuck trying to make a more cohesive app. What I could not figure out was how to use CRUDify's functionality without having to put all the options in the SiteMap. So I spent a lot of time trying to figure out the SiteMap class. I have since come to the realization that I probably shouldn't be using CRUDify, as non of the examples actually use it. I have also realized that I should be putting rules in LiftRules.rewrite. So, my point, I guess, is that it was never clear to me what request rewriting was all about. I didn't understand the explanations and basically just skipped it and tried to do everything with SiteMap. What I have taken away from this: Request Rewriting sounds very advanced and made me think of sendmail rewriting rules! (Yuck!) Maybe it would be good to have some blurbs on Lift for JEE developers. What is the equivalent of mapping a URL to a servlet and how do you deal with the URL pattern matching. (I want to map /foo/* to a some soft of action) So that would then be a nice lead-in to coverage of net.liftweb.http.S, right? Anyway, back to API docs, it never occurred to be to look at the docs for net.liftweb.http.LiftRules! There are actually lots of comments there. The rewrite is kinda hidden there, so it probably should be called out in the class docs. Then for the actual rewrite docs, it would be nice to give some examples of what should go in there or provide a link to external docs showing the same. How have other people tackled the learning curve of lift? --Andrew Derek Chen-Becker wrote: In terms of the API docs part of it would just be expanding on the current scaladoc to provider better explanation. Obviously there are a ton of classes to document, so I'd like to focus efforts on getting the most bang for the buck. I was thinking of starting with net.liftweb.http.{LiftRules,S,SHtml} and making the documentation on them *outstanding*. We can branch out from there. If you're coming to Lift new, it would also be helpful to find out what we're missing or need to cover better in the Getting Started document on the web site. If you want to read through that and provide feedback here on the list that would be great. Derek On Thu, Apr 30, 2009 at 12:20 PM, Andrew Scherpbier and...@scherpbier.org mailto:and...@scherpbier.org wrote: Derek, That's awesome. I want to help. What can I do? I can start by proof reading stuff. --Andrew --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to liftweb@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 -~--~~~~--~~--~--~---
Static imports considered evil? (was: Re: [Lift] Re: how to add object into session scope in lift)
I just realized another issue I keep running into... Since I don't have the full liftweb API in my head, yet, I am having trouble with some of the examples because of the use of ._ for imports (and this is why I never let my developers use static or wildcard imports in our own java code) For example, I was looking at the pocket change app's Boot.scala: case RewriteRequest(ParsePath(List(account, acctName), _, _, _), _, _) = RewriteResponse(viewAcct :: Nil, Map(name - urlDecode(acctName))) I was able to eventually find the docs for the RewriteRequest constructor and RewriteResponse constructor, but I have yet to find where urlDecode lives. From its camelCase, I presume it is a function in an object, so that means it is a static import. but which object? In eclipse, I'm used to having imports resolved and organized automatically when I save a file. Unfortunately, this same functionality doesn't appear to work in the eclipse scala plugin. Dunno if it is available in other IDEs. I know it is a PITA to do it by hand, but for the examples it might be worth it. --Andrew Derek Chen-Becker wrote: In terms of the API docs part of it would just be expanding on the current scaladoc to provider better explanation. Obviously there are a ton of classes to document, so I'd like to focus efforts on getting the most bang for the buck. I was thinking of starting with net.liftweb.http.{LiftRules,S,SHtml} and making the documentation on them *outstanding*. We can branch out from there. If you're coming to Lift new, it would also be helpful to find out what we're missing or need to cover better in the Getting Started document on the web site. If you want to read through that and provide feedback here on the list that would be great. Derek --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to liftweb@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: Static imports considered evil? (was: Re: [Lift] Re: how to add object into session scope in lift)
I've been trying to at least provide an object name for any methods like this in the example code as I work on feedback, but if you find any in the book that aren't clear please give me a listing # and I'll work on them. Thanks! Derek On Fri, May 1, 2009 at 7:27 AM, Andrew Scherpbier and...@scherpbier.orgwrote: I just realized another issue I keep running into... Since I don't have the full liftweb API in my head, yet, I am having trouble with some of the examples because of the use of ._ for imports (and this is why I never let my developers use static or wildcard imports in our own java code) For example, I was looking at the pocket change app's Boot.scala: case RewriteRequest(ParsePath(List(account, acctName), _, _, _), _, _) = RewriteResponse(viewAcct :: Nil, Map(name - urlDecode(acctName))) I was able to eventually find the docs for the RewriteRequest constructor and RewriteResponse constructor, but I have yet to find where urlDecode lives. From its camelCase, I presume it is a function in an object, so that means it is a static import. but which object? In eclipse, I'm used to having imports resolved and organized automatically when I save a file. Unfortunately, this same functionality doesn't appear to work in the eclipse scala plugin. Dunno if it is available in other IDEs. I know it is a PITA to do it by hand, but for the examples it might be worth it. --Andrew Derek Chen-Becker wrote: In terms of the API docs part of it would just be expanding on the current scaladoc to provider better explanation. Obviously there are a ton of classes to document, so I'd like to focus efforts on getting the most bang for the buck. I was thinking of starting with net.liftweb.http.{LiftRules,S,SHtml} and making the documentation on them *outstanding*. We can branch out from there. If you're coming to Lift new, it would also be helpful to find out what we're missing or need to cover better in the Getting Started document on the web site. If you want to read through that and provide feedback here on the list that would be great. Derek --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to liftweb@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: Static imports considered evil? (was: Re: [Lift] Re: how to add object into session scope in lift)
And yes, I consider wildcards to be not great style. They were done here for expediency, but I'll see about going back and reworking the code at some point. Derek On Fri, May 1, 2009 at 8:57 AM, Derek Chen-Becker dchenbec...@gmail.comwrote: I've been trying to at least provide an object name for any methods like this in the example code as I work on feedback, but if you find any in the book that aren't clear please give me a listing # and I'll work on them. Thanks! Derek On Fri, May 1, 2009 at 7:27 AM, Andrew Scherpbier and...@scherpbier.orgwrote: I just realized another issue I keep running into... Since I don't have the full liftweb API in my head, yet, I am having trouble with some of the examples because of the use of ._ for imports (and this is why I never let my developers use static or wildcard imports in our own java code) For example, I was looking at the pocket change app's Boot.scala: case RewriteRequest(ParsePath(List(account, acctName), _, _, _), _, _) = RewriteResponse(viewAcct :: Nil, Map(name - urlDecode(acctName))) I was able to eventually find the docs for the RewriteRequest constructor and RewriteResponse constructor, but I have yet to find where urlDecode lives. From its camelCase, I presume it is a function in an object, so that means it is a static import. but which object? In eclipse, I'm used to having imports resolved and organized automatically when I save a file. Unfortunately, this same functionality doesn't appear to work in the eclipse scala plugin. Dunno if it is available in other IDEs. I know it is a PITA to do it by hand, but for the examples it might be worth it. --Andrew Derek Chen-Becker wrote: In terms of the API docs part of it would just be expanding on the current scaladoc to provider better explanation. Obviously there are a ton of classes to document, so I'd like to focus efforts on getting the most bang for the buck. I was thinking of starting with net.liftweb.http.{LiftRules,S,SHtml} and making the documentation on them *outstanding*. We can branch out from there. If you're coming to Lift new, it would also be helpful to find out what we're missing or need to cover better in the Getting Started document on the web site. If you want to read through that and provide feedback here on the list that would be great. Derek --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to liftweb@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: how to add object into session scope in lift
Derek, That's awesome. I want to help. What can I do? I can start by proof reading stuff. --Andrew Derek Chen-Becker wrote: Updating docs are a high priority for me (an my TODO). I'm working on the proof copy of the APress book today and tomorrow but next week I'm going to start adding docs to the API. Derek On Wed, Apr 29, 2009 at 12:57 PM, Andrew Scherpbier and...@scherpbier.org mailto:and...@scherpbier.org wrote: I totally concur on the awesome explanation. As a matter of fact, can a committer add some of this stuff (maybe not the scala stuff but the actual explanation of the SessionVar) to the scaladocs of the SessionVar class/object? That would be a great place for this kind of documentation. rant disposition=friendly purpose=constructive criticism requested-outcome=discussion For me, the lack of usable scaladoc is really making it hard to learn lift. I've been toying with the idea of submitting patches to add docs as soon as I figure out some stuff... Problem is that it is going way too slow. A specific example would be the quote from section 6.2.4 in the Eploring Lift draft that reads: The CRUDify behavior is very flexible, with plenty of defs you can override to control the templates for pages... Then you go to the API docs for CRUDify and there are loads of cool defs, but no documentation what most of these do and what an override would get you. For the ones that have docs it is just a single line that doesn't really help that much. There is the source code. That's great. But unfortunately for me, Scala is still very much a write-only language since I'm still learning. I know that's my problem, but I know I'm not the only one! (I'm learning (and liking!) Scala because of Lift, just like lots of people learned Ruby because of Rails.) /rant So, I want to help, because I think Lift is just about the coolest thing out there, but it is going to take a while for me to be able to contribute. In the mean time, I would ask those in the know to try to add some docs to the code. BTW, this mailing list of great. The responses are *very* helpful. Keep them comin'! --Andrew Charles F. Munat wrote: Wow. This was super helpful even to a not-very-newbie. Thanks! Chas. David Pollak wrote: On Tue, Apr 28, 2009 at 11:07 PM, pravin karne pravinka...@gmail.com mailto:pravinka...@gmail.com mailto:pravinka...@gmail.com mailto:pravinka...@gmail.com wrote: hi, i want some explanation for following code object sessionObj extends SessionVar[HashMap[String, Int]]( new HashMap[String, Int] { override def default(key: String): Int = 0 } ) Changing a few things that Tim said. 1. how object extends class in scala.? object creates a singleton... an instance of the class that can be shared within the scope that it was created. If object is used at the top-level scope, then it is a singleton shared by all classes in that classloader (your Lift app.) In Scala everything is either an instance of an object or a method. This means there are no statics, no primitives, etc. In order to have a singleton instance shared within a classloader, use the object mechanism. 2. are we going to create object of SessionVar class? Yes, we create a singleton instance of the SessionVar class. The SessionVar class uses a little machinery to access the backing store of your session. So, the SessionVar doesn't actually store a value. It is a proxy that gets the current session based on the context of your thread, it has a globally unique name and uses this name to look up the underlying value in a hashmap in the session and then casts it to the type of the specific SessionVar... in this case HashMap[String, Int]. In this way, you have type-safe access to session data. This is a material advance over the way session data is stored in a Java session... there's no casting on the user's part. 3. are we calling constructor of given class? Yes. However, if you take a look at the SessionVar's constructor, it's as follows: class SessionVar[T](dflt: = T) This is a call-by-name parameter. So, it's a function rather than a value. Why do we do this? This allows us to create a new instance of the default value of the SessionVar each time it's needed. When you call the is method on the
[Lift] Re: how to add object into session scope in lift
hi, i want some explanation for following code object sessionObj extends SessionVar[HashMap[String, Int]]( new HashMap[String, Int] { override def default(key: String): Int = 0 } ) 1. how object extends class in scala.? 2. are we going to create object of SessionVar class? 3. are we calling constructor of given class? 4. is it similar to java class which extends other class ,and then create object of subclass? I am beginner to scala and lift. On Tue, Apr 28, 2009 at 7:28 PM, Timothy Perrett timo...@getintheloop.euwrote: Try: // this gets you whatever is in the session object so add to it here SessionObj.is Do you specifically need to use Java HashMap? If not, seems like List[(String,Int)] would be more lift-esq. Cheers, Tim On 28/04/2009 13:30, pravin pravinka...@gmail.com wrote: Hi guys, I want to add objects into session scope. i am using following code : object sessionObj extends SessionVar[HashMap[String, Int]]( new HashMap[String, Int] { override def default(key: String): Int = 0 } ) So as per my understanding :- 1. Session object is of HashMap[String, Int] type. 2. I want to add no of string object into above map so i can access them during my session correct me if i am wrong So please let me know how can i add/remove different String object from session scope with above code snippet Thanks in advance --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to liftweb@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: how to add object into session scope in lift
what is the is+ method sessionObj.is+ (foo - 1) how it differ from sessionObj.is(foo - 1) On Tue, Apr 28, 2009 at 8:33 PM, David Pollak feeder.of.the.be...@gmail.com wrote: On Tue, Apr 28, 2009 at 5:30 AM, pravin pravinka...@gmail.com wrote: Hi guys, I want to add objects into session scope. i am using following code : object sessionObj extends SessionVar[HashMap[String, Int]]( new HashMap[String, Int] { override def default(key: String): Int = 0 } ) So as per my understanding :- 1. Session object is of HashMap[String, Int] type. 2. I want to add no of string object into above map so i can access them during my session to add an object to this session var: sessionObj.is+ (foo - 1) sessionObj.is+ (bar - 88) if (sessionObj.is.contains(bar)) println(yes, it works) The only caveat is that HashMap is not thread-safe and you might be accessing this object from multiple threads at the same time. correct me if i am wrong So please let me know how can i add/remove different String object from session scope with above code snippet Thanks in advance -- Lift, the simply functional web framework http://liftweb.net Beginning Scala http://www.apress.com/book/view/1430219890 Follow me: http://twitter.com/dpp Git some: http://github.com/dpp --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to liftweb@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: how to add object into session scope in lift
1. Object is like a static class in Java but better. 2. Its not instantionation in that sense, so by proxy not creation 3. Scala objects have an apply method, of which, MyObject() is a shortcut to. Think of it as being the same as MyObject.apply(...) etc. 4. It is indeed a subtype similar to subclassing in Java. Does that help? Cheers, Tim On 29/04/2009 07:07, pravin karne pravinka...@gmail.com wrote: 1. how object extends class in scala.? 2. are we going to create object of SessionVar class? 3. are we calling constructor of given class? 4. is it similar to java class which extends other class ,and then create object of subclass? I am beginner to scala and lift. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to liftweb@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: how to add object into session scope in lift
On Tue, Apr 28, 2009 at 10:57 PM, pravin karne pravinka...@gmail.comwrote: what is the is+ method sessionObj.is+ (foo - 1) sessionObj.is gets the contained object from the SessionVar. In this case, that object is a HashMap. The + method is on HashMap: http://www.scala-lang.org/docu/files/api/scala/collection/mutable/HashMap.html how it differ from sessionObj.is(foo - 1) HashMap does not have an apply(p: Pair[??,??]) method, so this would not compile. On Tue, Apr 28, 2009 at 8:33 PM, David Pollak feeder.of.the.be...@gmail.com wrote: On Tue, Apr 28, 2009 at 5:30 AM, pravin pravinka...@gmail.com wrote: Hi guys, I want to add objects into session scope. i am using following code : object sessionObj extends SessionVar[HashMap[String, Int]]( new HashMap[String, Int] { override def default(key: String): Int = 0 } ) So as per my understanding :- 1. Session object is of HashMap[String, Int] type. 2. I want to add no of string object into above map so i can access them during my session to add an object to this session var: sessionObj.is+ (foo - 1) sessionObj.is+ (bar - 88) if (sessionObj.is.contains(bar)) println(yes, it works) The only caveat is that HashMap is not thread-safe and you might be accessing this object from multiple threads at the same time. correct me if i am wrong So please let me know how can i add/remove different String object from session scope with above code snippet Thanks in advance -- Lift, the simply functional web framework http://liftweb.net Beginning Scala http://www.apress.com/book/view/1430219890 Follow me: http://twitter.com/dpp Git some: http://github.com/dpp -- Lift, the simply functional web framework http://liftweb.net Beginning Scala http://www.apress.com/book/view/1430219890 Follow me: http://twitter.com/dpp Git some: http://github.com/dpp --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to liftweb@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: how to add object into session scope in lift
Wow. This was super helpful even to a not-very-newbie. Thanks! Chas. David Pollak wrote: On Tue, Apr 28, 2009 at 11:07 PM, pravin karne pravinka...@gmail.com mailto:pravinka...@gmail.com wrote: hi, i want some explanation for following code object sessionObj extends SessionVar[HashMap[String, Int]]( new HashMap[String, Int] { override def default(key: String): Int = 0 } ) Changing a few things that Tim said. 1. how object extends class in scala.? object creates a singleton... an instance of the class that can be shared within the scope that it was created. If object is used at the top-level scope, then it is a singleton shared by all classes in that classloader (your Lift app.) In Scala everything is either an instance of an object or a method. This means there are no statics, no primitives, etc. In order to have a singleton instance shared within a classloader, use the object mechanism. 2. are we going to create object of SessionVar class? Yes, we create a singleton instance of the SessionVar class. The SessionVar class uses a little machinery to access the backing store of your session. So, the SessionVar doesn't actually store a value. It is a proxy that gets the current session based on the context of your thread, it has a globally unique name and uses this name to look up the underlying value in a hashmap in the session and then casts it to the type of the specific SessionVar... in this case HashMap[String, Int]. In this way, you have type-safe access to session data. This is a material advance over the way session data is stored in a Java session... there's no casting on the user's part. 3. are we calling constructor of given class? Yes. However, if you take a look at the SessionVar's constructor, it's as follows: class SessionVar[T](dflt: = T) This is a call-by-name parameter. So, it's a function rather than a value. Why do we do this? This allows us to create a new instance of the default value of the SessionVar each time it's needed. When you call the is method on the SessionVar, Lift looks to see if the SessioVar has been defined. If it has not been defined, then the default value creator function is applied and we get a new default value, the SessionVar for the current session is set to that default value and the freshly minted value is returned. 4. is it similar to java class which extends other class ,and then create object of subclass? Scala creates a subclass of SessionVar for your singleton. If you do sessionObj.getClass.getName, it will not be SessionVar, but some compiler-generated name. See the answer to #1. I am beginner to scala and lift. Welcome to the community. Thanks, David On Tue, Apr 28, 2009 at 7:28 PM, Timothy Perrett timo...@getintheloop.eu wrote: Try: // this gets you whatever is in the session object so add to it here SessionObj.is Do you specifically need to use Java HashMap? If not, seems like List[(String,Int)] would be more lift-esq. Cheers, Tim On 28/04/2009 13:30, pravin pravinka...@gmail.com mailto:pravinka...@gmail.com wrote: Hi guys, I want to add objects into session scope. i am using following code : object sessionObj extends SessionVar[HashMap[String, Int]]( new HashMap[String, Int] { override def default(key: String): Int = 0 } ) So as per my understanding :- 1. Session object is of HashMap[String, Int] type. 2. I want to add no of string object into above map so i can access them during my session correct me if i am wrong So please let me know how can i add/remove different String object from session scope with above code snippet Thanks in advance -- Lift, the simply functional web framework http://liftweb.net Beginning Scala http://www.apress.com/book/view/1430219890 Follow me: http://twitter.com/dpp Git some: http://github.com/dpp --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to liftweb@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: how to add object into session scope in lift
I totally concur on the awesome explanation. As a matter of fact, can a committer add some of this stuff (maybe not the scala stuff but the actual explanation of the SessionVar) to the scaladocs of the SessionVar class/object? That would be a great place for this kind of documentation. rant disposition=friendly purpose=constructive criticism requested-outcome=discussion For me, the lack of usable scaladoc is really making it hard to learn lift. I've been toying with the idea of submitting patches to add docs as soon as I figure out some stuff... Problem is that it is going way too slow. A specific example would be the quote from section 6.2.4 in the Eploring Lift draft that reads: The CRUDify behavior is very flexible, with plenty of defs you can override to control the templates for pages... Then you go to the API docs for CRUDify and there are loads of cool defs, but no documentation what most of these do and what an override would get you. For the ones that have docs it is just a single line that doesn't really help that much. There is the source code. That's great. But unfortunately for me, Scala is still very much a write-only language since I'm still learning. I know that's my problem, but I know I'm not the only one! (I'm learning (and liking!) Scala because of Lift, just like lots of people learned Ruby because of Rails.) /rant So, I want to help, because I think Lift is just about the coolest thing out there, but it is going to take a while for me to be able to contribute. In the mean time, I would ask those in the know to try to add some docs to the code. BTW, this mailing list of great. The responses are *very* helpful. Keep them comin'! --Andrew Charles F. Munat wrote: Wow. This was super helpful even to a not-very-newbie. Thanks! Chas. David Pollak wrote: On Tue, Apr 28, 2009 at 11:07 PM, pravin karne pravinka...@gmail.com mailto:pravinka...@gmail.com wrote: hi, i want some explanation for following code object sessionObj extends SessionVar[HashMap[String, Int]]( new HashMap[String, Int] { override def default(key: String): Int = 0 } ) Changing a few things that Tim said. 1. how object extends class in scala.? object creates a singleton... an instance of the class that can be shared within the scope that it was created. If object is used at the top-level scope, then it is a singleton shared by all classes in that classloader (your Lift app.) In Scala everything is either an instance of an object or a method. This means there are no statics, no primitives, etc. In order to have a singleton instance shared within a classloader, use the object mechanism. 2. are we going to create object of SessionVar class? Yes, we create a singleton instance of the SessionVar class. The SessionVar class uses a little machinery to access the backing store of your session. So, the SessionVar doesn't actually store a value. It is a proxy that gets the current session based on the context of your thread, it has a globally unique name and uses this name to look up the underlying value in a hashmap in the session and then casts it to the type of the specific SessionVar... in this case HashMap[String, Int]. In this way, you have type-safe access to session data. This is a material advance over the way session data is stored in a Java session... there's no casting on the user's part. 3. are we calling constructor of given class? Yes. However, if you take a look at the SessionVar's constructor, it's as follows: class SessionVar[T](dflt: = T) This is a call-by-name parameter. So, it's a function rather than a value. Why do we do this? This allows us to create a new instance of the default value of the SessionVar each time it's needed. When you call the is method on the SessionVar, Lift looks to see if the SessioVar has been defined. If it has not been defined, then the default value creator function is applied and we get a new default value, the SessionVar for the current session is set to that default value and the freshly minted value is returned. 4. is it similar to java class which extends other class ,and then create object of subclass? Scala creates a subclass of SessionVar for your singleton. If you do sessionObj.getClass.getName, it will not be SessionVar, but some compiler-generated name. See the answer to #1. I am beginner to scala and lift. Welcome to the community. Thanks, David On Tue, Apr 28, 2009 at 7:28 PM, Timothy Perrett timo...@getintheloop.eu wrote: Try: // this gets you whatever is in the session object so add to it here SessionObj.is Do you specifically need to use Java HashMap? If not, seems like List[(String,Int)] would be more lift-esq. Cheers, Tim
[Lift] Re: how to add object into session scope in lift
Try: // this gets you whatever is in the session object so add to it here SessionObj.is Do you specifically need to use Java HashMap? If not, seems like List[(String,Int)] would be more lift-esq. Cheers, Tim On 28/04/2009 13:30, pravin pravinka...@gmail.com wrote: Hi guys, I want to add objects into session scope. i am using following code : object sessionObj extends SessionVar[HashMap[String, Int]]( new HashMap[String, Int] { override def default(key: String): Int = 0 } ) So as per my understanding :- 1. Session object is of HashMap[String, Int] type. 2. I want to add no of string object into above map so i can access them during my session correct me if i am wrong So please let me know how can i add/remove different String object from session scope with above code snippet Thanks in advance --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to liftweb@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: how to add object into session scope in lift
Or even scala.collection.Map ;) On Tue, Apr 28, 2009 at 7:58 AM, Timothy Perrett timo...@getintheloop.euwrote: Try: // this gets you whatever is in the session object so add to it here SessionObj.is Do you specifically need to use Java HashMap? If not, seems like List[(String,Int)] would be more lift-esq. Cheers, Tim On 28/04/2009 13:30, pravin pravinka...@gmail.com wrote: Hi guys, I want to add objects into session scope. i am using following code : object sessionObj extends SessionVar[HashMap[String, Int]]( new HashMap[String, Int] { override def default(key: String): Int = 0 } ) So as per my understanding :- 1. Session object is of HashMap[String, Int] type. 2. I want to add no of string object into above map so i can access them during my session correct me if i am wrong So please let me know how can i add/remove different String object from session scope with above code snippet Thanks in advance --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to liftweb@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: how to add object into session scope in lift
On Tue, Apr 28, 2009 at 5:30 AM, pravin pravinka...@gmail.com wrote: Hi guys, I want to add objects into session scope. i am using following code : object sessionObj extends SessionVar[HashMap[String, Int]]( new HashMap[String, Int] { override def default(key: String): Int = 0 } ) So as per my understanding :- 1. Session object is of HashMap[String, Int] type. 2. I want to add no of string object into above map so i can access them during my session to add an object to this session var: sessionObj.is+ (foo - 1) sessionObj.is+ (bar - 88) if (sessionObj.is.contains(bar)) println(yes, it works) The only caveat is that HashMap is not thread-safe and you might be accessing this object from multiple threads at the same time. correct me if i am wrong So please let me know how can i add/remove different String object from session scope with above code snippet Thanks in advance -- Lift, the simply functional web framework http://liftweb.net Beginning Scala http://www.apress.com/book/view/1430219890 Follow me: http://twitter.com/dpp Git some: http://github.com/dpp --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to liftweb@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 -~--~~~~--~~--~--~---