[Lift] Re: submit and redirect

2009-02-02 Thread Tim Perrett


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-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-02 Thread Derek Chen-Becker
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

On Mon, Feb 2, 2009 at 8:00 AM, Derek Chen-Becker dchenbec...@gmail.comwrote:

 I think the convention is to either properly capitalize the snippet tag to
 match the class name, as you've done, or to use underscores to indicate
 camel case, a la

 show_market

 I don't think that Lift handles mixed camel case, but it's been a while
 since I've looked at that part of the code.

 Derek


 On Sun, Feb 1, 2009 at 9:20 AM, Sergey Andreev andser...@gmail.comwrote:

 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.comwrote:

 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.comwrote:


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

2009-01-30 Thread Marius



On Jan 30, 2:14 pm, Sergey Andreev andser...@gmail.com wrote:
 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.

Lift knows which functions to invoke upon a request based on the query
string parameters. I'm not sure why this matters so much. However if
you really don't want to do that then you explicitly need to keep your
state on server side most typically using SessionVar-s. Write your
state in a SessionVar before redirect and read it in your snippets
for /show template.

I proposed the above solution because it is way cleaner IMO and the
redirect function is automatically cleaned up ;)


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

2009-01-30 Thread Marius

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-01-29 Thread Derek Chen-Becker
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 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)
 }

 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-29 Thread Marius



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