Nothing to see here, move along please. This blog is only used to allow me to communicate between my tablets and my PCs.

Monday, November 12, 2007


(provisional title)



Tasks (in no particular order)

1. 'Deskify' Karrigell

The idea is to be able to run a web application just like running a Windows application. A 'deskified' Karrigell application should start from a Windows shortcut and it should shut down just like a windows application when it exits or is closed from within the browser.

Write a wrapper for Karrigell that starts a Karrigell server and then opens a web-page in the default browser that loads a specified page from the just started server. The wrapper also needs to specify a dedicated port number (not 80) for use by the server. All pages loaded will have to use that port number.

The wrapper is also responsible for terminating the Karrigell server when it receives notification from the web application that it is shutting down.

The lifetime of the Karrigell server is the lifetime of underlying application. Multiple applications can be run, but each will have their own dedicated Karrigell server - think of Karrigell as part of the application's run-time rather than as a traditional web server.

2. Termination trap

Write some JavaScript that can intercept an attempt by the user to close a page's tab or the browser displaying the page.

Ans: This is html. There is an event handler "onunload" containing JavaScript as an attribute in the <body> tag.

Put this in a file called trap1.html, then open it with a browser:

The lone arranger
<body onUnLoad="alert('this is a wrap!')">
This is a wrap.

Display a dialog box that asks the user if they really want to close this page or to continue.

We can intercept the unload event, but we cannot seem to stop it happening. There must be some way of doing this...
We can call more JavaScript to save things etc. and perhaps open a new browser tab/window with the old page
Ans: save this as trap2.html

<TITLE>OnUnLoad example</TITLE>
function goodbyeornot(){
if (confirm("Do you want to exit?"))
alert("Thanks for Visiting!");
// I also tried: location = "trap2.html";
<BODY onUnLoad="goodbyeornot()">
<H3>Example of onUnload event handler</H3>
Look what happens when you try to leave this page...

Redo the same code in GWT Java. This probably means wrapping up the JavaScript from above into a Java package that probably uses JSNI.

The termination trap is used to prevent inadvertent loss of application data should the user close a tab or a browser instance without saving changes and exiting the application. It might be more interesting to use the idea of saving the application state periodically so that re-opening a browser on that application can recover the application state exactly as it was when the browser was closed.

Google Docs and Spreadsheets seems to do both: if you try to close a tab that contains an unsaved document then you get the warning pop-up, but if the document has been saved or auto-saved then it lets you go ahead silently. The back button also works to restore the tab to its former state. So does the re-open closed tab in Firefox. Pretty nice.

3. Sample GWT application

Write a simple GWT 'applet' and 'servlet' that:

  • Displays a form that requests a 'name' from the user, sends that name to the servlet packaged up initially in a GWT RPC call.
  • The servlet responds with telephone number for that name, or xxx-xxx-xxxx if the name is unknown. Only a couple of names are required.
  • Intercepts any attempt to shutdown the applet by closing the browser window/tab with an 'are you sure?' dialog box. If confirmed then the applet makes an RPC call to the servlet and tells the servlet that the applet has shutdown. The servlet logs this event to the console.

Once this is running OK, then the applet needs to be changed to use XMLHTTPRequest and JSON instead of the standard GWT RPC protocol. Build a version of the servlet that responds to these requests instead of the RPC calls.

JSON is the 'payload' protocol discussed in the above link. You will need to find a JSON decoder (parser) for Java - which should not be too difficult.

I will probably want to use JSON-RPC in Python so take a look at this and see if you can get this going in Java.

4. Sample Python Servlet

Recreate the Java servlet from 3. using Python running under Karrigel.

No comments: