Implementing a Firefox Plugin for Tapestry’s Reset Service

Implementing a Firefox Plugin for Tapestry’s Reset Service
Actually, i decided to make this a greasemonkey script, instead of a full FF plugin…

So, here’s the process:

  • 12:25. Install greasemonkey. ( http://greasemonkey.mozdev.org/ )
  • 12:27 Restart Firefox
  • 12:28 Search for a good tutorial on writing greasemonkey scripts.
  • 12:32 Hmm, http://greasemonkey.mozdev.org/authoring.html is a starting point, as is the http://mozdev.elliptic.fr/greasemonkey/linkify.user.js example.
  • 12:33 Create a file named tapestry.user.js somewhere. Open it up in an editor and also in FF. Make your changes in the editor, refresh in FF and click on install to use it.
  • 12:37 After the first hello world examples, let’s create something that adds an absolute positioned div in the current page, containing a static link for the moment.
  • 12:41 I used document.createElement(‘div’) to create the div and document.getElementsByTagName(“body”)[0].appendChild(resetDiv) to add it in the dom.
  • 12:44 I can write links in the div… with the ugly way (hope Jesse isn’t reading this), i.e. resetDiv.innerHTML='<a href=”…”>Cool</a>’
  • 12:45 location.href gives us the current url. we’ll have to hack it a bit to contruct a valid Tapestry reset url. For now, we’ll keep the url from the beggining to the last occurance of slash ‘/’ and append app?service=reset&page=Home afterwards.
  • 12:50 Done! Here’s the result.

Remember to configure the script so that it’s active only on the pages you want. Further updates might:

  • Recognize Tapestry sites and auto-enable the plugin.
  • Recognize and use the current page so that you won’t get redirected to Home.
  • Use better styling for the added div… It should be on the top of the page, with absolute positioning and semi-transparent.
  • See if this also works in Tapestry 3.

So, watch out for an update on this!

P.S.1 You have to enable Tapestry’s reset service for this to work.
P.S.2 If you’re wondering why you need this, then read on : )

While editing Tapestry’s templates (*.html) or configuration files (*.page, *.jwc, *.application, *.library) you can get instant save-refresh functionality if you disable cache (that’s org.apache.tapestry.disable-caching ). This however slows down request handling by a noticable amount and results in memory leaks because classloaders are thrown away on each request. I generally wouldn’t mind about this since it’s only used on development and it takes a LOT of refreshes before one gets an OutOfMemoryException.

But if you’re on AJAX ( read tacos or tapestry 4.1 ) then you’ll get that exception a lot more faster. So, in the last few months I’ve got into the habit of enabling cache + enabling the reset service ( that’s org.apache.tapestry.enable-reset-service. I usually keep an extra tab open in Firefox (having the url of the reset service) and whenever I make changes I hit refresh on that tab (so that all templates and Tapestry configurations are reloaded) and then return to my normal tab.

P.S.3 This was initially written in my internal TiddlyWiki, an awesome javascript-only wiki. I was really surprised when Howard recently commited (!!!) this wiki in Tapestry 5 trunk. In fact, I never knew a wiki could get itself committed! Well done Jeremy.