Log in

No account? Create an account
current entries friends' entries archives about me Previous Previous Next Next
Okay, let's talk tech - cellophane — LiveJournal
the story of an invisible girl
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....

Current Music: Michael Penn - romeo In Black Jeans

read 7 comments | talk to me!
devnul From: devnul Date: March 21st, 2006 12:25 pm (UTC) (Link)
A techie blog would be a great idea, but your company would probably find it highly wrong, so if you do it, keep it private. For pretty much anyone I know, anything developed on company time and hardware, any great or slick or neat idea, technically belongs to the company.

Of course, we all know that we do take our ideas from one job to another, be it a slick garbage collector or the means to manage a tty in a forked child or other such subtleties, but it's best to not really publicize that, if you know what I mean.
bjorng From: bjorng Date: March 21st, 2006 01:25 pm (UTC) (Link)
Sounds nice and simple, really. I had to do something similar a while ago (perhaps before XMLHttpRequest was available?). It wasn't terribly complicated, but the code was not pretty.

I'd be very interested in a techie blog, but devnul's warnings in that regard are probably valid.
specialagentm From: specialagentm Date: March 21st, 2006 02:40 pm (UTC) (Link)
Well, I'm listening.

I forwarded this to my group. We've thought of doing something like this ourselves, and I know a couple of the other guys are working up some little AJAX stuff...
pstscrpt From: pstscrpt Date: March 21st, 2006 03:14 pm (UTC) (Link)
Sometimes I wonder if I shouldn't make myself a techie blog, to keep track of random little projects like this

I'd read it, but then I'm in the process of changing from a VB/SQL Server developer to a Java/Oracle developer.
zenmondo From: zenmondo Date: March 21st, 2006 04:54 pm (UTC) (Link)
I don't mind techy posts in this journal. In fact I enjoyed it a great deal. I don't think you need a techie blog.
operatic From: operatic Date: March 21st, 2006 09:09 pm (UTC) (Link)
It's a fun technology, isn't it? I'm enjoying working with AJAX (so far ;) ). :)
theobviousname From: theobviousname Date: March 23rd, 2006 04:37 am (UTC) (Link)
I'm not sure I'm sold on this AJAX thing. After 6 months, I'm really starting to think I'd rather be writing a proper application. AJAX just means you've got one more piece that needs to be separately debugged...

So I'm trying to debug why the splitter pane I'm working on is appearing with the correct width, but zero height. I have Venkman open, to step through the Javascript, I have the DOM Inspector open, so I can re-check the CSS every time I refresh the view, and of course I have IDEA open to trace the portal code and a log appender running to watch for Tomcat errors. Venkman is passable (I cut my teeth on adb; I _can_ cope with basic), but it's no IDEA, and Javascript's class-extension syntax seems somewhat contrived. The DOM Inspector has to be refreshed in order to notice that the DOM on the page has been re-written. And this is an *easy* bug - I can reproduce it in Firefox. Woe betied those of us who have to debug an IE-only problem.

If this were a stand-alone application, it'd just be a matter of registering a Listener against the splitter bar, updating its position and letting everything repaint around it. Yeah, okay, but this works in a web browser. We could also make a car that could be driven from any seat, but is it really worth the bother?

(The problem, in case you're wondering, turns out to be mostly on the portal side; the CSS is only providing heights for the *contents* of the splitter pane, which is nested two DIVs below the splitter; the Javascript only sizes based on direct children and the intermediate level is an artifact of using a zero-width DIV for the splitter bar, so it doesn't have its own layout step to pass the height info up. Width, of course, *is* assigned to the three DIVs that comprise the splitter (left, bar, right), because that's how the bar is positioned.)
read 7 comments | talk to me!