Backbutton for Ajax

52 views
Skip to first unread message

greekscala

unread,
Jan 11, 2010, 4:55:21 PM1/11/10
to Lift
Hello Lift people!

I would like to know how experienced lift devs think and what they do
about
ajax backbutton support.

with best regards

Marius

unread,
Jan 11, 2010, 5:02:31 PM1/11/10
to Lift
Could you please be more specific? ... what use case are you thinking
of?

Br's,
Marius

Alex Boisvert

unread,
Jan 11, 2010, 5:05:35 PM1/11/10
to lif...@googlegroups.com
I've been playing with sammy.js recently and I like the way they update the URL fragment identifier (hash) when doing AJAX which makes apps more back-button friendly, in a manner that's similar to GMail.

It would be nice to have something similar in Lift.

alex


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




greekscala

unread,
Jan 11, 2010, 6:10:26 PM1/11/10
to Lift
Hello Marius,

I have some pages that will be located over a normal url.
But then there will be ajax interaction. I would like to
have the backbutton work in this situations.

best regards

greekscala

unread,
Jan 11, 2010, 6:13:03 PM1/11/10
to Lift
Hello Alex!

I will take a look at sammy.js .
I would like to have some way for this in Lift too.
Since with Lift it is easy to do alot of ajax.

with best regards

On 11 Jan., 23:05, Alex Boisvert <alex.boisv...@gmail.com> wrote:
> I've been playing with sammy.js <http://code.quirkey.com/sammy/> recently


> and I like the way they update the URL fragment identifier (hash) when doing
> AJAX which makes apps more back-button friendly, in a manner that's similar
> to GMail.
>
> It would be nice to have something similar in Lift.
>
> alex
>

> On Mon, Jan 11, 2010 at 4:55 PM, greekscala <hellectro...@gmail.com> wrote:
> > Hello Lift people!
>
> > I would like to know how experienced lift devs think and what they do
> > about
> > ajax backbutton support.
>
> > with best regards
>
> > --
> > 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<liftweb%2Bunsu...@googlegroups.com>

Timothy Perrett

unread,
Jan 11, 2010, 6:35:23 PM1/11/10
to lif...@googlegroups.com
I'm not sure what is stopping you using something like this in
conjunction with lift?

If you want something baked in, can you be specific with what and how
you might want it to work?

Cheers, Tim

Sent from my iPhone

greekscala

unread,
Jan 12, 2010, 7:23:25 AM1/12/10
to Lift
Hello Timothy,

there is nothing stoping me from using it.
But when I think of a framework it would be nice to "activate"
backbutton support.
I think this is somethink a lot of people would appreciate to have and
not everybody
should have to build this from the ground up.

I do not have to deal with this now but in near future. I will have to
search
what ways are avalable. And if I can intergrate this im my app, maybe
we
can find a way to abstract it.

with best regards

On 12 Jan., 00:35, Timothy Perrett <timo...@getintheloop.eu> wrote:
> I'm not sure what is stopping you using something like this in  
> conjunction with lift?
>
> If you want something baked in, can you be specific with what and how  
> you might want it to work?
>
> Cheers, Tim
>
> Sent from my iPhone
>

greekscala

unread,
Jan 13, 2010, 5:45:49 PM1/13/10
to Lift
Hello,

I would really would like to have this type of support from lift.
I looked at GWT and think this is a nice way. They use url parameters
after a '#'. I dont understand the process because I have very little
javascript knowledge.

But I am thinking, lift is creating unique function names and is
calling them with ajax.
Maybe there is a way to have the functions be called over a way like
GWT?

Just creating some thoughts...

best regards

Alex Boisvert

unread,
Jan 13, 2010, 9:02:55 PM1/13/10
to lif...@googlegroups.com
Just thinking out loud as to how this could work...

On modern browsers, it's possible to monitor the state change of the browser's URL hash (aka window.location.hash /  '#' / document fragment) in the browser with the 'onhashchange' DOM event.  It gets fired whenever the location.hash changes.  On older browsers, it's also possible to poll for change which is less efficient but that's life.

So the idea would be to:

1) add a snippet or utility method to set up a listener on onhashchange that would callback Scala functions associated with given hash (e.g. #foo, #bar, ...).  Hashes could support parameters too (e.g., #foo/:param1/:param2)

2) add a method S.ajaxHash(hashPath, callback): JsCmd that would bind a hash path/pattern to a Scala function (by registering the path/pattern with the listener)

3) add a method S.changeHash(hashPath, params): JsCmd to programmatically change the browser's hash as a result of some AJAX processing.

I don't have time to work on this yet but I'd be happy to hear what others think of the idea.

alex

To unsubscribe from this group, send email to liftweb+u...@googlegroups.com.

Naftoli Gugenheim

unread,
Jan 13, 2010, 9:10:08 PM1/13/10
to lif...@googlegroups.com
I haven't really used Ajax much but it seems to me there are two kinds of changes.
1. Modifying the view, e.g., clicking an emal in Gmail, or Expand All. One can make an analogy to a GET request, in that there's no permanent change.
2. Taking actions, e.g., invoking an action on the server, or deleting the viewed email in Gmail. The analogy would be to a POST.
It seems to me that Lift's Ajax is often used for #2. However backbutton support doesn't really make sense in that scenario.


-------------------------------------
Alex Boisvert<alex.b...@gmail.com> wrote:

alex

> liftweb+u...@googlegroups.com<liftweb%2Bunsu...@googlegroups.com>


> > > > .
> > > > For more options, visit this group athttp://
> groups.google.com/group/liftweb?hl=en
> > > > .
>
> --
> 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<liftweb%2Bunsu...@googlegroups.com>


> .
> For more options, visit this group at
> http://groups.google.com/group/liftweb?hl=en.
>
>
>
>
--
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.

Alex Boisvert

unread,
Jan 14, 2010, 10:29:52 AM1/14/10
to lif...@googlegroups.com
On Wed, Jan 13, 2010 at 6:10 PM, Naftoli Gugenheim <nafto...@gmail.com> wrote:
I haven't really used Ajax much but it seems to me there are two kinds of changes.
1. Modifying the view, e.g., clicking an emal in Gmail, or Expand All. One can make an analogy to a GET request, in that there's no permanent change.
2. Taking actions, e.g., invoking an action on the server, or deleting the viewed email in Gmail. The analogy would be to a POST.
It seems to me that Lift's Ajax is often used for #2. However backbutton support doesn't really make sense in that scenario.

I think the split between 1/2 depends greatly on your application.  I'd say the backbutton is as useful for POST as it is for GET.   It's a navigation tool and sometimes the best way to get where you want is to go back two steps and forward in another direction.   Mind you, it's still more complicated to handle actions (POST) is a safe manner.  The back button doesn't undo and if you go forward the same way, you may trigger a duplicate action.   It's up to the application to handle such cases.

I think this is applicable to the wizard stuff too.   I think back button support would be a very nice usability enhancement there.

alex

Naftoli Gugenheim

unread,
Jan 14, 2010, 10:52:25 AM1/14/10
to lif...@googlegroups.com
If you press delete then back what will happen?

-------------------------------------
Alex Boisvert<alex.b...@gmail.com> wrote:

alex

Alex Boisvert

unread,
Jan 14, 2010, 11:03:56 AM1/14/10
to lif...@googlegroups.com
Depends on your application.  What would it do if it wasn't implemented with AJAX?

This isn't a magical feature.   It's a feature that allows you to support the back button 1) if it makes sense to you and 2) if you can figure out a way to make it safe for the user.

For example, you click the delete button.  The snippet is replaced by "Item deleted".  You click back button, now you're back to the item you deleted.  If you go back again, maybe you go back to the list of items you were working with and from there you can go delete others.   So it's just a navigation tool to support existing web idioms.

alex

Timothy Perrett

unread,
Jan 14, 2010, 11:11:55 AM1/14/10
to Lift
Just came across this:

http://github.com/Marak/route.js

Might be interesting food for thought as it strikes me that would hook
into lifts function based javascript quite nicely.

Cheers, Tim

On Jan 14, 4:03 pm, Alex Boisvert <alex.boisv...@gmail.com> wrote:
> Depends on your application.  What would it do if it wasn't implemented with
> AJAX?
>
> This isn't a magical feature.   It's a feature that allows you to support
> the back button 1) if it makes sense to you and 2) if you can figure out a
> way to make it safe for the user.
>
> For example, you click the delete button.  The snippet is replaced by "Item
> deleted".  You click back button, now you're back to the item you deleted.
> If you go back again, maybe you go back to the list of items you were
> working with and from there you can go delete others.   So it's just a
> navigation tool to support existing web idioms.
>
> alex
>

> On Thu, Jan 14, 2010 at 7:52 AM, Naftoli Gugenheim <naftoli...@gmail.com>wrote:
>
>
>
> > If you press delete then back what will happen?
>
> > -------------------------------------

> > Alex Boisvert<alex.boisv...@gmail.com> wrote:
>
> > On Wed, Jan 13, 2010 at 6:10 PM, Naftoli Gugenheim <naftoli...@gmail.com

> > liftweb+u...@googlegroups.com<liftweb%2Bunsu...@googlegroups.com >


> > .
> > For more options, visit this group at
> >http://groups.google.com/group/liftweb?hl=en.
>
> > --
> > 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<liftweb%2Bunsu...@googlegroups.com >

Alex Boisvert

unread,
Jan 14, 2010, 1:00:29 PM1/14/10
to lif...@googlegroups.com
Yep, that's pretty similar in spirit to sammy.js and what I was describing. 

alex

To unsubscribe from this group, send email to liftweb+u...@googlegroups.com.

Naftoli Gugenheim

unread,
Jan 14, 2010, 1:14:16 PM1/14/10
to lif...@googlegroups.com
You mean there would be something like a back button callback that would let you do anything you do in a lift callback?

-------------------------------------
Alex Boisvert<alex.b...@gmail.com> wrote:

Depends on your application. What would it do if it wasn't implemented with
AJAX?

This isn't a magical feature. It's a feature that allows you to support
the back button 1) if it makes sense to you and 2) if you can figure out a
way to make it safe for the user.

For example, you click the delete button. The snippet is replaced by "Item
deleted". You click back button, now you're back to the item you deleted.
If you go back again, maybe you go back to the list of items you were
working with and from there you can go delete others. So it's just a
navigation tool to support existing web idioms.

alex


On Thu, Jan 14, 2010 at 7:52 AM, Naftoli Gugenheim <nafto...@gmail.com>wrote:

> If you press delete then back what will happen?
>
> -------------------------------------

> Alex Boisvert<alex.b...@gmail.com> wrote:
>
> On Wed, Jan 13, 2010 at 6:10 PM, Naftoli Gugenheim <nafto...@gmail.com

David Pollak

unread,
Jan 14, 2010, 1:29:45 PM1/14/10
to lif...@googlegroups.com
On Wed, Jan 13, 2010 at 6:02 PM, Alex Boisvert <alex.b...@gmail.com> wrote:
Just thinking out loud as to how this could work...

On modern browsers, it's possible to monitor the state change of the browser's URL hash (aka window.location.hash /  '#' / document fragment) in the browser with the 'onhashchange' DOM event.  It gets fired whenever the location.hash changes.  On older browsers, it's also possible to poll for change which is less efficient but that's life.

So the idea would be to:

1) add a snippet or utility method to set up a listener on onhashchange that would callback Scala functions associated with given hash (e.g. #foo, #bar, ...).  Hashes could support parameters too (e.g., #foo/:param1/:param2)

2) add a method S.ajaxHash(hashPath, callback): JsCmd that would bind a hash path/pattern to a Scala function (by registering the path/pattern with the listener)

3) add a method S.changeHash(hashPath, params): JsCmd to programmatically change the browser's hash as a result of some AJAX processing.

I don't have time to work on this yet but I'd be happy to hear what others think of the idea.

I really like this approach... too bad you don't have time to work on it. :-(
 



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

Alex Boisvert

unread,
Jan 14, 2010, 1:36:18 PM1/14/10
to lif...@googlegroups.com
Yes.  If you click the back button, the hash changes from, say, #current to #back, and then the callback associated with #back gets called.   It could, for example, rerender the snippet in its previous state.

alex

Marius

unread,
Jan 14, 2010, 3:11:15 PM1/14/10
to Lift
+1 for this approach but I'd rather opt it for JsCmd cases classes/
objects and not really S/SHtml methods.

case class AjaxHash extends JsCmd {
...
}

you got the idea.

Br's,
Marius

On Jan 14, 8:29 pm, David Pollak <feeder.of.the.be...@gmail.com>
wrote:


> On Wed, Jan 13, 2010 at 6:02 PM, Alex Boisvert <alex.boisv...@gmail.com>wrote:
>
>
>
> > Just thinking out loud as to how this could work...
>
> > On modern browsers, it's possible to monitor the state change of the
> > browser's URL hash (aka window.location.hash /  '#' / document fragment)
> > in the browser with the 'onhashchange' DOM event.  It gets fired whenever
> > the location.hash changes.  On older browsers, it's also possible to poll
> > for change which is less efficient but that's life.
>
> > So the idea would be to:
>

> > 1) add a snippet or utility method to set up a listener on onhashchangethat would callback Scala functions associated with given hash (e.g. #foo,


> > #bar, ...).  Hashes could support parameters too (e.g.,
> > #foo/:param1/:param2)
>
> > 2) add a method S.ajaxHash(hashPath, callback): JsCmd that would bind a
> > hash path/pattern to a Scala function (by registering the path/pattern with
> > the listener)
>
> > 3) add a method S.changeHash(hashPath, params): JsCmd to programmatically
> > change the browser's hash as a result of some AJAX processing.
>
> > I don't have time to work on this yet but I'd be happy to hear what others
> > think of the idea.
>
> I really like this approach... too bad you don't have time to work on it.
> :-(
>
>
>
>
>
> > alex
>

> >> liftweb+u...@googlegroups.com<liftweb%2Bunsu...@googlegroups.com>


> >> > > > .
> >> > > > For more options, visit this group athttp://
> >> groups.google.com/group/liftweb?hl=en
> >> > > > .
>
> >> --
> >> 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<liftweb%2Bunsu...@googlegroups.com>


> >> .
> >> For more options, visit this group at
> >>http://groups.google.com/group/liftweb?hl=en.
>
> > --
> > 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<liftweb%2Bunsu...@googlegroups.com>


> > .
> > For more options, visit this group at
> >http://groups.google.com/group/liftweb?hl=en.
>
> --

> Lift, the simply functional web frameworkhttp://liftweb.net

> Beginning Scalahttp://www.apress.com/book/view/1430219890

Reply all
Reply to author
Forward
0 new messages