S.notice and RedirectTo

123 views
Skip to first unread message

Mads Hartmann Jensen

unread,
Nov 3, 2010, 6:27:25 AM11/3/10
to lif...@googlegroups.com
Hey guys,

usually when I use S.notice and friends it goes something like this

...calculations...
S.notice("W00t, all went well")
redirectTo("meaningful/page")

Now I'm in a situation where the redirect is a javascript RedirectTo instead and the S.notice(..) doesn't show up. I should say that this
is inside a CometActor and the code is like this:

val url = ....
S.notice("Succesfully saved things")
partialUpdate(RedirectTo(url))

First off, is this the expected behavior that the notice doesn't show?

If it is I think it would be nice to add something like

RedirectToWithNotices(List[Box[String]])
RedirectToWithErrors(List[Box[String]])
.... etc.

or at least something that would allow for a js redirect and show a message.

Thanks,
Mads Hartmann Jensen

David Brooks

unread,
Nov 3, 2010, 8:35:23 AM11/3/10
to lif...@googlegroups.com
Hi Mads,

On 3 Nov 2010, at 10:27, Mads Hartmann Jensen wrote:

> usually when I use S.notice and friends it goes something like this
>
> ...calculations...
> S.notice("W00t, all went well")
> redirectTo("meaningful/page")
>
> Now I'm in a situation where the redirect is a javascript RedirectTo instead and the S.notice(..) doesn't show up. I should say that this
> is inside a CometActor and the code is like this:
>
> val url = ....
> S.notice("Succesfully saved things")
> partialUpdate(RedirectTo(url))
>
> First off, is this the expected behavior that the notice doesn't show?

Anecdotal evidence only, but when I've done this kind of thing with AJAX the notice doesn't show up.

I've taken to using the following pattern, but I can't remember where I acquired it. I think it was a thread on this list, but I can't find it in my local mail.

RedirectTo(S.mapFuncToURI(url, () => {
S.notice(msg)
S.redirectTo(url)
}))

I've not tried it with Comet, but it works with AJAX redirects.

That said, some sugar for this would be welcomed :)

Cheers,
D

Mads Hartmann Jensen

unread,
Nov 4, 2010, 7:19:49 AM11/4/10
to lif...@googlegroups.com
Thanks David,

Looks promising, will try it out.

Mads Hartmann

> --
> You received this message because you are subscribed to the Google Groups "Lift" group.
> To post to this group, send email to lif...@googlegroups.com.
> To unsubscribe from this group, send email to liftweb+u...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/liftweb?hl=en.
>

Daniel Hobi

unread,
Dec 9, 2010, 2:46:19 AM12/9/10
to Lift
Thanks for that David. Just needed that bit of code today!

> Anecdotal evidence only, but when I've done this kind of thing with AJAX the notice doesn't show up
My guess why it behaves this way:
S.notice / warning / error works the same way for ajax and "common
http" requests. So if you fill S.error in a ajax request, the ajax
response itself will contain and therefore bind the error messages on
the current page (S messages are cleared). Unfortunately, our response
contains a RedirectTo too and just jumps away from the current page to
our target page.

So I think that S.notice / warning / error do show up but only for a
very limited time.

Daniel

On 3 Nov., 13:35, David Brooks <davidjamesbro...@gmail.com> wrote:
> Hi Mads,
>
> On 3 Nov 2010, at 10:27, Mads Hartmann Jensen wrote:
>
> > usually when I useS.notice and friends it goes something like this
>
> > ...calculations...
> >S.notice("W00t, all went well")
> > redirectTo("meaningful/page")
>
> > Now I'm in a situation where theredirectis a javascript RedirectTo instead and theS.notice(..) doesn't show up. I should say that this

David Pollak

unread,
Dec 9, 2010, 7:40:17 AM12/9/10
to lif...@googlegroups.com
On Wed, Dec 8, 2010 at 11:46 PM, Daniel Hobi <d.h...@gmx.ch> wrote:
Thanks for that David. Just needed that bit of code today!

> Anecdotal evidence only, but when I've done this kind of thing with AJAX the notice doesn't show up
My guess why it behaves this way:
S.notice / warning / error works the same way for ajax and "common
http" requests. So if you fill S.error in a ajax request, the ajax
response itself will contain and therefore bind the error messages on
the current page (S messages are cleared). Unfortunately, our response
contains a RedirectTo too and just jumps away from the current page to
our target page.

So I think that S.notice / warning / error do show up but only for a
very limited time.

Lift 2.2-RC1 has RedirectTo(page, () => function).  You can put whatever notices you need in () => function.
 

Daniel

On 3 Nov., 13:35, David Brooks <davidjamesbro...@gmail.com> wrote:
> Hi Mads,
>
> On 3 Nov 2010, at 10:27, Mads Hartmann Jensen wrote:
>
> > usually when I useS.notice and friends it goes something like this
>
> > ...calculations...
> >S.notice("W00t, all went well")
> > redirectTo("meaningful/page")
>
> > Now I'm in a situation where theredirectis a javascript RedirectTo instead and theS.notice(..) doesn't show up. I should say that this
> > is inside a CometActor and the code is like this:
>
> > val url = ....
> >S.notice("Succesfully saved things")
> > partialUpdate(RedirectTo(url))
>
> > First off, is this the expected behavior that the notice doesn't show?
>
> Anecdotal evidence only, but when I've done this kind of thing with AJAX the notice doesn't show up.
>
> I've taken to using the following pattern, but I can't remember where I acquired it. I think it was a thread on this list, but I can't find it in my local mail.
>
> RedirectTo(S.mapFuncToURI(url, () => {
>  S.notice(msg)
>  S.redirectTo(url)
>
> }))
>
> I've not tried it with Comet, but it works with AJAX redirects.
>
> That said, some sugar for this would be welcomed :)
>
> Cheers,
> D

--
You received this message because you are subscribed to the Google Groups "Lift" group.
To post to this group, send email to lif...@googlegroups.com.
To unsubscribe from this group, send email to liftweb+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/liftweb?hl=en.




--
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Blog: http://goodstuff.im
Surf the harmonics

Mads Hartmann Jensen

unread,
Dec 9, 2010, 7:52:12 AM12/9/10
to lif...@googlegroups.com
Great! :)
Reply all
Reply to author
Forward
0 new messages