[Lift] Re: How do I properly read a value from a cookie?

2009-11-16 Thread Sergey Andreev
Hi,

For-comprehensions could help you out:

for{
  cookie - S.findCookie(cookieName)
  value - cookie} doSomethingWithValue

Regards

On Mon, Nov 16, 2009 at 12:07 PM, DMB combust...@gmail.com wrote:


 When I call findCookie it returns a Box. Then, the value on the cookie
 itself is also a box. Hence a ruby one-liner turns into something
 like:

 val cookie = S.findCookie(cookieName)
 if(cookie.isDefined) {
 val cookieVal = cookie.open_!.value.openOr(null)
 // Do something with the cookie value
 }

 This is very ugly, so I'm guessing I'm doing something wrong, but try
 as I might, I could not find any examples that would look even vaguely
 right to me.

 Why can't findCookie return a simple, unboxed HTTPCookie object or
 null if cookie is not found?
 Why does the value inside a cookie need to also be Box'ed?

 For the sake of comparison, here's how you do the same thing in RoR:
 v = cookies[cookieName]
 // Do something with the cookie

 or ASP.NET:
 var c = Request.Cookies[CookieName]
 if(c != null) {
   var v = c.Value
   // Do something with the cookie
 }

 I fail to see why Lift should be more complicated.

 This is with Lift 1.1 M7
 


--~--~-~--~~~---~--~~
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: Object typecast to Mapper

2009-04-20 Thread Sergey Andreev
Hi Amit,

Try that one

  def bindObject[T : AnyRef](className: Class[T]): Option[Object] = {
val sClassName =
className.getPackage.getName.concat(.Wrap.concat(className.getSimpleName))
try {
  Some(Class.forName(sClassName.replaceFirst(com.vtech,
com.vtech.appxtension)).newInstance.asInstanceOf[T])
} catch {
  case e: Exception =
try {
  Some(Class.forName(className.getName).newInstance.asInstanceOf[T])
} catch {
  case e1: Exception  =
println(e1.printStackTrace)
None
}
}
  }

Regards,

Sergey

On Mon, Apr 20, 2009 at 3:41 PM, Amit Kumar Verma cdac.a...@gmail.comwrote:


 Hi All,

 This is a sample function for making an object from string at run
 time. Here we are not casting the object but creating one. I wanted
 the same thing for casting the object.

 public static Object bindObject(Class className) {
Object objOutput = null;
try {
String sClassName = className.getPackage().getName().concat
 (.Wrap.concat(className.getSimpleName()));
objOutput = Class.forName(sClassName.replaceFirst
 (com.vtech, com.vtech.appxtension)).newInstance();
} catch (Exception e) {
try {
objOutput = Class.forName(className.getName
 ()).newInstance();
} catch (Exception e1) {
e1.printStackTrace();
}
}

return objOutput;
}


 Thanks to all for kind support..
 Amit Kumar Verma

 On Apr 18, 8:51 pm, Timothy Perrett timo...@getintheloop.eu wrote:
  So your talking about reflection right? Take a look at scala Manifests
  (which aide getting round type erasure) - other than that scala supports
 all
  the normal reflection tooling that Java does.
 
  Tim
 
  On 18/04/2009 06:56, Amit Kumar Verma cdac.a...@gmail.com wrote:
 
   Scala is a static language, so the class for casting must be known at
   compile time.  It's not possible to construct a String at runtime and
   cast
   an object into a class represented by that String. 
 
   But we use this feature in Java for casting the objects.

 


--~--~-~--~~~---~--~~
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: StatefulSnippet Beginner

2009-04-18 Thread Sergey Andreev
Could you attach a sample code which doesn't work?

On Sat, Apr 18, 2009 at 8:41 PM, bradford fingerm...@gmail.com wrote:


 I have changed class Products {  to read class Products extends
 StatefulSnippet {

 Instead of S.redirectTo, I now have this.redirectTo and it still
 doesn't seem to be saving the state.


 On Apr 17, 10:55 pm, Derek Chen-Becker dchenbec...@gmail.com wrote:
  OK, first, your snippet class needs to extend StatefulSnippet. Then you
 need
  to define the dispatch partial function to tell it which snippet goes to
  which function, and then you need to use StatefulSnippet.link and
  StatefulSnippet.redirectTo instead of SHtml.link and S.redirectTo,
  respectievly.
 
  Derek
 
  On Fri, Apr 17, 2009 at 7:45 PM, bradford fingerm...@gmail.com wrote:
 
   I'm trying to play around with the StatefulSnippets and can't get it
   to hold state.  This is what I have for a test:
 
   class Products {
object productVar extends RequestVar(new Product())
def selectedProduct = productVar.is
 
def search(xhtml: Group): NodeSeq = {
  var query = ;
 
  def processSearch() = {
// hard code id for now
val product = Model.createNamedQuery[Product](findProductById,
   (id - 1L)).getSingleResult()
Log.info(processSearch:   + product.id.toString) // prints 1
productVar(product)
Log.info(post processSearch:   + product.id.toString) //
   prints 1
 
S.redirectTo(select.html)
  }
 
  val plAttrs = List((size, 40), (maxlength, 80), (style,
   width: 98%))
  bind(f, xhtml,
   query - SHtml.text(query, query = _),
   submit - SHtml.submit(Search, processSearch)
  )
}
 
def selectedQuery(xhtml: NodeSeq): NodeSeq = {
  Log.info(selectedProduct:   + selectedProduct.id.toString) //
   HELP!:  prints 0
  Text(selectedProduct.name(en_US) match { case Some(a) = a.name
   case None = No Product Found})
}
   }
 


--~--~-~--~~~---~--~~
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: Custom Boot Class

2009-03-16 Thread Sergey Andreev
Jorge,

I am using a custom Boot class and it works just fine. I believe that if you
create a Brat.scala and put your class there, it will solve the problem

Regards,
Sergey

On Mon, Mar 16, 2009 at 1:31 PM, Jorge Ortiz jorge.or...@gmail.com wrote:

 Folks,

 I'm trying to specify a custom Boot class, as per Chapter 3 of the Lift
 Book. To my web.xml I've added:

   context-param
 param-namebootloader/param-name
 param-valuebootstrap.liftweb.Brat/param-value
   /context-param

 and in Boot.scala I've commented out the regular Boot class and added a
 Brat class with identical implementation, except it extends Bootable.

   class Brat extends Bootable { ... }

 Unfortunately, I'm getting a:

   ERROR - Failed to Boot
   java.lang.ClassNotFoundException: bootstrap.liftweb.Boot

 Attached is the zipped project.

 Thanks,

 --j

 


--~--~-~--~~~---~--~~
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: submit and redirect

2009-02-02 Thread Sergey Andreev
There were no errors on the console. And the state was persisted when i was
using Marius's example. So it looks like a bug to me.
Thanks,
Sergey

On Mon, Feb 2, 2009 at 6:09 PM, Tim Perrett he...@timperrett.com wrote:



 Lift will still indeed notify you of an error invoking a snippet.

 On 02/02/2009 15:01, Derek Chen-Becker dchenbec...@gmail.com wrote:

  Also, if the class for the snippet couldn't be found, Lift should have
 output
  a message to that effect on the console. If it didn't, then that's a bug.
 
  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: submit and redirect

2009-02-01 Thread Sergey Andreev
Derek,
I was commenting out everything from my snippet and template but still the
state was lossing between after redirect. And then i decided to change the
name of the template from index.html to add.html (any other name) and it
magically worked. Looks like a bug to me. Will investigate the sources
further.
Thanks for your help,
Sergey

On Fri, Jan 30, 2009 at 11:44 PM, Derek Chen-Becker
dchenbec...@gmail.comwrote:

 Right, really the same mechanism in different guises. Still, the code that
 Sergey sent should work as far as I can tell...

 Derek


 On Fri, Jan 30, 2009 at 11:01 AM, Marius marius.dan...@gmail.com wrote:


 Yeah it does... in essence not very different from initial proposal
 since internally redirectTo from stateful snippet does the same thing:
 binds a function to be executed upon redirect.

 On Jan 30, 5:47 pm, Derek Chen-Becker dchenbec...@gmail.com wrote:
  Unless I'm missing something the stateful snippet should be working. The
  this.redirectTo call should be invoking the StatefulSnippet's
 redirectTo,
  which should associate the same snippet instance with the new page. That
  should allow access to the same var. I just coded up a test app
 (attached)
  and it works fine using very similar code.
 
  On Fri, Jan 30, 2009 at 12:36 AM, Marius marius.dan...@gmail.com
 wrote:
 
   On Jan 29, 10:54 pm, Sergey Andreev andser...@gmail.com wrote:
Hi Liftlers,
I am migrating one of my application to the lift as a way to learn
 it and
   i
would like to ask a question.
 
After submitting a form i would like to do a redirect and show the
   submitted
values on the other template. I have 2 templates and i use the same
   snippet
in both of them to render a dynamic content.
As far as i understand there are 2 ways to make it work: saving
 state
   using
SessionVars(which works for me) or extending StatefulSnippet and
 calling
this.redirectTo on it (looking at the sources it should register the
stateful snippet in the session). I've tried extending
 StatefulSnippet
   but
it doesn't work for me. A hashed value is added to the redirect url
 which
should map to the stateful snippet but the state is lost. I don't
   understand
what i am doing wrong.
 
The simplified example of the code:
 
class MySnippet extend StatefulSnippet {
  private var myValues: List[String] = List()
 
  val dispatch.. = {
case save = save_
case show = show _
  }
 
  def show = {
myValues.foreach(Log.info(_)) //nothing here
  }
 
  def save(xhtml: NodeSeq) : NodeSeq = {
def processForm = {
  myValues.foreach(Log.info(_)) //submitted values are printed
 out
  this.redirectTo(/show)
}
 
   Unless I'm missing something I do not this your values can be shown in
   the new template. There is an overloaded S.redirectTo where you can
   specify a function to be executed when the redirect is receives. Hence
   here you can pass state. See
 
   def redirectTo[T](where: String, func: () = Unit): T
 
   In this function you could probably set some RequestVar holding your
   needed state and when you snippet is rendered in the /show page you
   just read the info from these RequestVar(s).
 
bind(render, xhtml,
   .. //render textboxes and register functions which add
 values
   to
the myValues list
   submit - submit(Submit, processForm)
  }
 
}
 
Thanks,
Sergey
P.S. The more i learn about Lift the more i like it. Thank you David
 and
   all
lift committers!!!
 
 
 
   teststateful.tgz
  7KViewDownload



 


--~--~-~--~~~---~--~~
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: submit and redirect

2009-02-01 Thread Sergey Andreev
The problem has nothing to do with templates names.
I was writting lift:showMarket.show.../lift:showMarket.show

Capitalizing the first letter in the snippet's name (lift:ShowMarket.show)
solved the problem. Anyway looks like a bug =)

Regards,
Sergey


On Sun, Feb 1, 2009 at 7:09 PM, Sergey Andreev andser...@gmail.com wrote:

 Derek,
 I was commenting out everything from my snippet and template but still the
 state was lossing between after redirect. And then i decided to change the
 name of the template from index.html to add.html (any other name) and it
 magically worked. Looks like a bug to me. Will investigate the sources
 further.
 Thanks for your help,
 Sergey

 On Fri, Jan 30, 2009 at 11:44 PM, Derek Chen-Becker dchenbec...@gmail.com
  wrote:

 Right, really the same mechanism in different guises. Still, the code that
 Sergey sent should work as far as I can tell...

 Derek


 On Fri, Jan 30, 2009 at 11:01 AM, Marius marius.dan...@gmail.com wrote:


 Yeah it does... in essence not very different from initial proposal
 since internally redirectTo from stateful snippet does the same thing:
 binds a function to be executed upon redirect.

 On Jan 30, 5:47 pm, Derek Chen-Becker dchenbec...@gmail.com wrote:
  Unless I'm missing something the stateful snippet should be working.
 The
  this.redirectTo call should be invoking the StatefulSnippet's
 redirectTo,
  which should associate the same snippet instance with the new page.
 That
  should allow access to the same var. I just coded up a test app
 (attached)
  and it works fine using very similar code.
 
  On Fri, Jan 30, 2009 at 12:36 AM, Marius marius.dan...@gmail.com
 wrote:
 
   On Jan 29, 10:54 pm, Sergey Andreev andser...@gmail.com wrote:
Hi Liftlers,
I am migrating one of my application to the lift as a way to learn
 it and
   i
would like to ask a question.
 
After submitting a form i would like to do a redirect and show the
   submitted
values on the other template. I have 2 templates and i use the same
   snippet
in both of them to render a dynamic content.
As far as i understand there are 2 ways to make it work: saving
 state
   using
SessionVars(which works for me) or extending StatefulSnippet and
 calling
this.redirectTo on it (looking at the sources it should register
 the
stateful snippet in the session). I've tried extending
 StatefulSnippet
   but
it doesn't work for me. A hashed value is added to the redirect url
 which
should map to the stateful snippet but the state is lost. I don't
   understand
what i am doing wrong.
 
The simplified example of the code:
 
class MySnippet extend StatefulSnippet {
  private var myValues: List[String] = List()
 
  val dispatch.. = {
case save = save_
case show = show _
  }
 
  def show = {
myValues.foreach(Log.info(_)) //nothing here
  }
 
  def save(xhtml: NodeSeq) : NodeSeq = {
def processForm = {
  myValues.foreach(Log.info(_)) //submitted values are printed
 out
  this.redirectTo(/show)
}
 
   Unless I'm missing something I do not this your values can be shown
 in
   the new template. There is an overloaded S.redirectTo where you can
   specify a function to be executed when the redirect is receives.
 Hence
   here you can pass state. See
 
   def redirectTo[T](where: String, func: () = Unit): T
 
   In this function you could probably set some RequestVar holding your
   needed state and when you snippet is rendered in the /show page you
   just read the info from these RequestVar(s).
 
bind(render, xhtml,
   .. //render textboxes and register functions which add
 values
   to
the myValues list
   submit - submit(Submit, processForm)
  }
 
}
 
Thanks,
Sergey
P.S. The more i learn about Lift the more i like it. Thank you
 David and
   all
lift committers!!!
 
 
 
   teststateful.tgz
  7KViewDownload



 



--~--~-~--~~~---~--~~
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] bug in mixinAttributes

2009-01-30 Thread Sergey Andreev
Hi,
I have encountered a bug in the mixinAttributes method

If you put the following xml in the template:

data:textBoxes
 input type=text style=.../
/data:textBoxes

and bind it like that: bind(data, xhtml, textBoxes -
mixinAttributes(text(,)) _)
then the attributes won't be merged.

Whereas, if you change the template:
data:textBoxesinput type=text style=.../
/data:textBoxes

attributes are merged. The problem is that in the first template, the child
NodeSeq of the textBoxes element has a first element without attributes so
the following line returns Null

val attributes = in.firstOption.map(_.attributes).getOrElse(Null)

I made a hack with filtering in's elements on having non-null attributes
with non-zero length before applying firstOption.
It would be nice if that bug will be addressed in the future releases.

Regards,
Sergey

--~--~-~--~~~---~--~~
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: submit and redirect

2009-01-30 Thread Sergey Andreev
Marius, thanks for the code sample. I read your mails about that usage of
the redirectTo method on the list before but was confused how to use it. I
wish there was a way to hide function's hash code from the URL without
losing state.
Cheers,
Sergey

On Fri, Jan 30, 2009 at 10:40 AM, Marius marius.dan...@gmail.com wrote:




 On Jan 30, 9:36 am, Marius marius.dan...@gmail.com wrote:
  On Jan 29, 10:54 pm, Sergey Andreev andser...@gmail.com wrote:
 
 
 
   Hi Liftlers,
   I am migrating one of my application to the lift as a way to learn it
 and i
   would like to ask a question.
 
   After submitting a form i would like to do a redirect and show the
 submitted
   values on the other template. I have 2 templates and i use the same
 snippet
   in both of them to render a dynamic content.
   As far as i understand there are 2 ways to make it work: saving state
 using
   SessionVars(which works for me) or extending StatefulSnippet and
 calling
   this.redirectTo on it (looking at the sources it should register the
   stateful snippet in the session). I've tried extending StatefulSnippet
 but
   it doesn't work for me. A hashed value is added to the redirect url
 which
   should map to the stateful snippet but the state is lost. I don't
 understand
   what i am doing wrong.
 
   The simplified example of the code:
 
   class MySnippet extend StatefulSnippet {
 private var myValues: List[String] = List()
 
 val dispatch.. = {
   case save = save_
   case show = show _
 }
 
 def show = {
   myValues.foreach(Log.info(_)) //nothing here
 }
 
 def save(xhtml: NodeSeq) : NodeSeq = {
   def processForm = {
 myValues.foreach(Log.info(_)) //submitted values are printed out
 this.redirectTo(/show)
   }
 
  Unless I'm missing something I do not this your values can be shown in
  the new template. There is an overloaded S.redirectTo where you can
  specify a function to be executed when the redirect is receives. Hence
  here you can pass state. See
 
  def redirectTo[T](where: String, func: () = Unit): T
 
  In this function you could probably set some RequestVar holding your
  needed state and when you snippet is rendered in the /show page you
  just read the info from these RequestVar(s).


 To me more specific I was referring to something like:


 def myFunc(state: List[String])() { // a curried function

   // here set the state on a RequestVar

 }

 from you submit function call:

 S.redirectTo(/show, myFunc(myValues) _)


 
 
 
   bind(render, xhtml,
  .. //render textboxes and register functions which add
 values to
   the myValues list
  submit - submit(Submit, processForm)
 }
 
   }
 
   Thanks,
   Sergey
   P.S. The more i learn about Lift the more i like it. Thank you David
 and all
   lift committers!!!
 


--~--~-~--~~~---~--~~
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] submit and redirect

2009-01-29 Thread Sergey Andreev
Hi Liftlers,
I am migrating one of my application to the lift as a way to learn it and i
would like to ask a question.

After submitting a form i would like to do a redirect and show the submitted
values on the other template. I have 2 templates and i use the same snippet
in both of them to render a dynamic content.
As far as i understand there are 2 ways to make it work: saving state using
SessionVars(which works for me) or extending StatefulSnippet and calling
this.redirectTo on it (looking at the sources it should register the
stateful snippet in the session). I've tried extending StatefulSnippet but
it doesn't work for me. A hashed value is added to the redirect url which
should map to the stateful snippet but the state is lost. I don't understand
what i am doing wrong.

The simplified example of the code:

class MySnippet extend StatefulSnippet {
  private var myValues: List[String] = List()

  val dispatch.. = {
case save = save_
case show = show _
  }

  def show = {
myValues.foreach(Log.info(_)) //nothing here
  }

  def save(xhtml: NodeSeq) : NodeSeq = {
def processForm = {
  myValues.foreach(Log.info(_)) //submitted values are printed out
  this.redirectTo(/show)
}

bind(render, xhtml,
   .. //render textboxes and register functions which add values to
the myValues list
   submit - submit(Submit, processForm)
  }
}

Thanks,
Sergey
P.S. The more i learn about Lift the more i like it. Thank you David and all
lift committers!!!

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---