Persisting State Across Server Restarts

已查看 31 次
跳至第一个未读帖子

James Muerle

未读,
2016年3月29日 16:53:282016/3/29
收件人 Lift
Hi community,

I've been working on a project where we're trying to solve the following problem:

A user is on our site, filling out a form. While they are doing so, we restart our server with an update. When the user submits the form (through liftAjax), they get an unmapped parameter exception.

Our current working solution is to record the actions the user takes on the page (client-side) until we detect an unmapped parameter, and then refresh the page and re-perform the last action taken. To preserve the state of any fields on the page, we will be pushing data onto the window history. The problem I've found, though, is that I'm not able to tell the client side through a response that we had an unmapped parameter on the server side. The handleUnmappedParameter LiftRules vendor does not allow for a return type, so the only thing it can do is redirect the page with S.redirectTo or with a ResponseShortcutException. Is there a way to give a special response to the client in the case of an unmapped parameter? Is there entirely another way that I should be solving this problem?

Thanks for all of your times,
James

Antonio Salazar Cardozo

未读,
2016年3月29日 17:24:382016/3/29
收件人 Lift
The nice thing about ResponseShortcutException is that it allows you to
return an arbitrary response. So you can also return a JavaScriptResponse:

throw ResponseShortcutException.shortcutResponse(
  JavaScriptResponse(Call("reloadAndDoMagic").cmd)
)

That should run reloadAndDoMagic() on the client as a response to
the unmapped parameter.

Does that help?
Thanks,
Antonio

James Muerle

未读,
2016年3月30日 15:00:272016/3/30
收件人 Lift
Yeah, I saw that I could return an arbitrary response, so I tried to return a JsonResponse, but I was getting a server 500 error. I switched to using your code and I'm getting the same thing. Let me know if that's expected, because I'm assuming at the moment that we are somehow catching the exception by accident. It's weird, though, because S.redirectTo is working just fine, and as far as I know that uses ResponseShortcutException as well.

By the way, thanks for the prompt response!
James

James Muerle

未读,
2016年3月30日 18:05:022016/3/30
收件人 Lift
After a bit of investigation, I've found the minimal change that would cause the problem I'm encountering.

ResponseShortcutException has three arguments: Response callback, Redirect address Box, and a notify boolean. No matter what the response is, it seems that the ajax call will result in a 500 if the redirect box is Empty, and otherwise result in a success with the js response of "\nwindow.location = 'your string';". That is why S.redirectTo was working as intended, but when I tried making my own response it wouldn't work.

We are currently on Lift version 2.6, and it looks like this issue was addressed here: https://github.com/lift/framework/issues/1638.

Thanks for all your help,
James

Antonio Salazar Cardozo

未读,
2016年3月31日 00:11:082016/3/31
收件人 Lift
Nice find! I confess I'd completely forgotten about that issue and its
fix. Glad you figured out how to get it done even on 2.6 :)
Thanks,
Antonio
回复全部
回复作者
转发
0 个新帖子