Re: [Lift] robust form posting in high availability configuration

64 views
Skip to first unread message

Diego Medina

unread,
Sep 19, 2012, 2:56:43 PM9/19/12
to lif...@googlegroups.com
I haven't tried this, but have been thinking of.
How about using HTML5 storage, there are a few APi out there, so, as
the user enters data in the forms, you store the data on the client,
and then, your submit button can call a JS function that collects
those values, and submits them, with something like jsonCall.

So, if the users enters data in 10 fields, clicks submit, the server
crashes, , he/she reloads the page, the old data will be there, and
the new submit will go to the live server.

For info on reading fields and sending them with jsonCall, see
https://fmpwizard.telegr.am/blog/adding-fields-dynamically-lift

Regards,

Diego


On Wed, Sep 19, 2012 at 11:40 AM, jean rossier <jean.r...@gmail.com> wrote:
> Hello,
>
> I'm developing a web application mainly composed of forms to display/insert
> various information about events. So far, I was working with a single server
> (Jetty) that was deploying my app.
> Now, I want to add some high availability and rolling upgrade features. For
> that, I follow the guidelines of Thimothy Perrett in his book (Lift in
> action, chapter 15). I now have two instance of my app running, and an NGINX
> server above them that does the load balancing. And it works pretty well.
> However, since I have many forms that are filled by the users, I would like
> that if one server crashes while a user in entering some data, the data is
> not lost when the user presses "submit".
> So far, I've mostly used Ajax forms
> (http://simply.liftweb.net/index-4.8.html) and they work very well with a
> single server. But with my new configuration (two servers, load-balanced),
> if the server that is serving my current page crashes while I'm filling up a
> form, it breaks the normal behavior. The submit button has actually no
> action. I thus have to reload the full page (that will be served by the
> second server), re-enter my data and submit the form. That will work, but it
> is very annoying for the user.
> I also tested with non-ajax forms and RequestVar
> (http://simply.liftweb.net/index-4.4.html) but the behavior is the same.
>
> My question is thus the following: Is there a way in Lift (with my
> configuration: two server, load-balanced) to have "robust" forms (data is
> not lost when a server crashes while a user is filling up a form) ? if yes,
> how ?
>
> Thanks for the help,
> Jean
>
> --
> --
> Lift, the simply functional web framework: http://liftweb.net
> Code: http://github.com/lift
> Discussion: http://groups.google.com/group/liftweb
> Stuck? Help us help you:
> https://www.assembla.com/wiki/show/liftweb/Posting_example_code
>
>
>



--
Diego Medina
Lift/Scala Developer
di...@fmpwizard.com
http://www.fmpwizard.com

Antonio Salazar Cardozo

unread,
Sep 19, 2012, 3:09:23 PM9/19/12
to lif...@googlegroups.com
We actually do this. You can customize the code that runs when a session is lost using the LiftRules.noAjaxSessionCmd FactoryMaker as of Lift 2.5-M1. We use the code at http://openstudy.com/javascripts/reload-handling.js to run window.serverReload() when the page is reloaded by the server. That function stashes the contents of inputs and then restores them on page load. It has to deal with some complexities of our URI handling, and uses jStore, which is a probably-outdated API to normalize client-side storage handling across browsers. But, it should provide a decent guide.
Thanks,
Antonio

Ben Phelan

unread,
Sep 22, 2012, 1:27:08 PM9/22/12
to lif...@googlegroups.com
That is so awesome.

Antonio Salazar Cardozo

unread,
Sep 26, 2012, 1:12:50 PM9/26/12
to lif...@googlegroups.com
Here it is:

      // It's important to do this in order to control our own session loss
      // scenario.
      LiftRules.redirectAsyncOnSessionLoss = true
      LiftRules.noCometSessionCmd.default.set(new JE.JsRaw("window.serverReload ? window.serverReload() : window.location.reload();") with JsCmd)

The serverReload function is defined in the JS file I linked above. Pretty simple stuff on the Lift end :)
Thanks,
Antonio

On Wednesday, September 26, 2012 4:08:03 AM UTC-4, jean rossier wrote:
Hello Antonio,

thanks for your reply ! Your solution seems to be exactly what I'm looking for.
Could you give me a bit more details on how you execute your custom code using LiftRules.noAjaxSessionCmd ? 
Are you calling a JsCmd directly ? 

Thanks for the help
Jean


On Wednesday, September 19, 2012 9:09:23 PM UTC+2, Antonio Salazar Cardozo wrote:

Antonio Salazar Cardozo

unread,
Sep 26, 2012, 1:13:24 PM9/26/12
to lif...@googlegroups.com
(We do ours on comet session loss; you can do yours on Ajax session loss, of course.)
Antonio
Reply all
Reply to author
Forward
0 new messages