alpaca princess (renniekins) wrote,
alpaca princess
renniekins

  • Music:

Okay, let's talk tech

I completed my "second" AJAX project today, although really my first project is still only mostly-done. So this is actually the second, but the first to go into QA.

It's a nifty little app.

See, our web server is required to have a 60 minute timeout. Sometimes users will be taking a call, an affidavit, and they'll be talking and writing in the NOTES app for more than 60 minutes. They're typing, but they're not making any web server calls. So essentially the web server doesn't know they're still working.

Suddenly, much to their horror, a "the server timed out" popup box appears. When they click OK, they are logged out of the system and they lose all their notes.

It sucks, as you can imagine. They can't periodically save their note, because for legal reasons no note can be edited, and it can only be saved when it is complete. For the same legality, we really shouldn't save auto-drafts... although we may revisit that idea later on.

The solution is simple. A javascript timer. 5 minutes before they'll time out, a popup appears. "Are you still using this thing?" If the user clicks OK, an XMLHttpRequest calls and "pings" the server. (XMLHttpRequest, that's really all that Ajax is. The rest is javascript, smoke, and mirrors.)

Why do we use Ajax? A "regular" action won't work, because we don't want the user to switch or refresh screens. We just want to tell the server that we're still using it.

Anyway my server ping is a Struts action. It supplies a short XML file into the response's OutputStream then returns null. (Interesting side note: just calling an action wasn't sufficient. I had to actually put something into the HttpServletResponse to get this to work consistently.

There is no need to return an ActionForward, because Ajax just want to update a piece of an existing web page, not go to a new one. (There is even a nice 2-part JUnit test around this action, although I confess I didn't write it first.)

The last bit is javascript, which processes the server's response. It checks the XML data. Does it contain what it expected? Then all is well, and the user can get back to work.

If the XML data does NOT contain what we were looking for, then the server really did timeout. The user walked away, had another window on top, was at lunch, whatever -- they didn't click OK within the required 5 minutes. So we pop up an apologetic message, log them out, and send them back to the login screen.

Short and sweet! There are fancier solutions out there, but I think this minimal one will take care of things for now. (I can provide code samples to the curious reader, if this quick summary interested anyone.)

Sometimes I wonder if I shouldn't make myself a techie blog, to keep track of random little projects like this....
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 7 comments