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



[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:


 


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

Whereas, if you change the template:



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
Derek,
The templates are quite simple:
fist one:








second one:

 //other attributes are ommitted



Sergey

On Fri, Jan 30, 2009 at 10:01 AM, Derek Chen-Becker
wrote:

> That looks like it should be working, but could you post the template(s)
> that go along with this?
>
> Derek
>
>
> On Thu, Jan 29, 2009 at 1:54 PM, Sergey Andreev 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")
>> }
>>
>> 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] 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  wrote:

>
>
>
> On Jan 30, 9:36 am, Marius  wrote:
> > On Jan 29, 10:54 pm, Sergey Andreev  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] 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
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  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  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 
>> wrote:
>> >
>> > > On Jan 29, 10:54 pm, Sergey Andreev  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 ...

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

Regards,
Sergey


On Sun, Feb 1, 2009 at 7:09 PM, Sergey Andreev  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  > 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  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  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 
>>> wrote:
>>> >
>>> > > On Jan 29, 10:54 pm, Sergey Andreev  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-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  wrote:

>
>
> Lift will still indeed notify you of an error invoking a snippet.
>
> On 02/02/2009 15:01, "Derek Chen-Becker"  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: 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  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:
>
>   
> bootloader
> bootstrap.liftweb.Brat
>   
>
> 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: Custom Boot Class

2009-03-16 Thread Sergey Andreev
Jorge,
it looks like that i have kept Boot class in the place that is why it was
working fine for me. Thanks for spotting before i got problems in production
:-)

Derek, you are absolutely right. In the LiftFilter.init method,  we get
bootloader parameter from the FilterConfig object instead of ServletContext.

So, changing config to context in the following line solves the problem on
my machine:
bootLift(Box.legacyNullTest(context.getInitParameter("bootloader")))

Cheers,
Sergey

On Mon, Mar 16, 2009 at 4:58 PM, Derek Chen-Becker wrote:

> I wonder if this is something that broke when we moved to a Filter...
>
> Derek
>
>
> On Mon, Mar 16, 2009 at 7:02 AM, Jorge Ortiz wrote:
>
>> I get the same error, unfortunately.
>>
>> --j
>>
>>
>> On Mon, Mar 16, 2009 at 4:48 AM, Sergey Andreev wrote:
>>
>>> 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 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:
>>>>
>>>>   
>>>> bootloader
>>>> bootstrap.liftweb.Brat
>>>>   
>>>>
>>>> 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: Constructor for Req in custom dispatch functions

2009-04-15 Thread Sergey Andreev
Look at the unapply method on a Req object

On Wed, Apr 15, 2009 at 4:17 PM, Heiko Seeberger <
heiko.seeber...@googlemail.com> wrote:

> Hi,
> In the current version of Exploring Lift Listing 3.20 shows an example of a
> custom dispatch function:
>
> LiftRules.dispatch.append {
>   case Req(chart :: balances :: endDate :: Nil, _, _) => ...
>
> How does this work? I cannot find a constructor for Req taking these
> parameters (a List as first one).
>
> Thanx
> --
> Heiko Seeberger
> www.heikoseeberger.name
> OSGi on Scala
>
> >
>

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

>
> 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  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"  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: Box and Option - what am I missing?

2009-05-04 Thread Sergey Andreev
Import net.liftweb.util.Box._ and you should get option2Box implicit

On Mon, May 4, 2009 at 5:44 PM, TSP  wrote:

>
> I've a function that returns an Option. How do I turn it into a box.
> I'm told there are implicit functions to do so, so why doesn't the
> following code work and what do I need to do to it please?
>
> import net.liftweb.util.{Failure, Full, Box}
> def myOpt(hasSome: boolean) = {
>  if (hasSome)
>Some("got it")
>  else
>None
> }
>
> val noFailure = myOpt(true) ?~ "shouldn't see me"
> println(noFailure)
> val aFailure = myOpt(false) ?~ "should fail"
> println(aFailure)
>
> Tim
> >
>

--~--~-~--~~~---~--~~
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 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  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: How do I properly read a value from a cookie?

2009-11-16 Thread Sergey Andreev
To avoid null checking. If there is no cookie, you will get Empty otherwise
Full(cookie). Moreover with for-comprehensions you don't need any checks at
all. If there is no cookie then the doSomethingWithValue won't be evaluated.

On Mon, Nov 16, 2009 at 12:34 PM, DMB  wrote:

>
> I guess that could work, but why go to such lengths where there are
> much more straightforward solutions available? What do for
> comprehensions buy you in this case? I mean, 99% of the time, when I
> want to check for a cookie, I don't need the cookie itself or any of
> its properties. I need its value, or null if there's no cookie. Why
> not do something a-la RoR:
>
> S.cookieValue("cookieName")
>
> or a-la ASP.NET:
>
> val c = S.cookie("cookieName")
> if(c != null) {
>   val v = c.value
> }
>
> Or, indeed, both?
>
> On Nov 16, 1:22 am, Sergey Andreev  wrote:
> > 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  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
-~--~~~~--~~--~--~---