Wednesday, May 6, 2009

Vertical and horizontal flow panels in GWT

If you're anything like me, you probably hate the fact the the vertical and horizontal panels in GWT are implemented using tables. Not only does this make styling the resulting HTML pure hell, it also makes it unnecessarily complicated.

So here's something we can use for a pure div layout:



The source is also up at github.

The horizontal flow panel will, of course, wrap when there isn't any place left to go. But its a lot easier to style than the awful mess it throws up with tables.

Friday, November 28, 2008

Event delegation works like a charm

A lot of discussions have been going on about binding events to elements after DOM load - like elements we load using AJAX or create in response to other events... there's also plugins for jQuery which help out with this like livequery, but I prefer to use event delegation instead...

Take a look at the little snippet Dan Webb has put up... I use it a lot and love its simplicity. It's here.

The examples he's provided are good enough, but as an additional example here's a snippet from PinnSpot:


http://pastie.org/325872

The #points div is what keeps getting loaded with stuff dynamically, both by other events and by AJAX calls... so any of the clicks inside it are only handled at the top level. This saves having to bind 4 X 20 = 80 or so events... and rebinding them every 10 seconds or so.

The $(e.target) lets you find the exact HTML element that was clicked... i.e. its what 'this' would be if we bind the event directly on each element. So it pretty much gives you everything you had when binding each event on its own. Also remember that the events here don't bubble up... so even when the ".edit" element is inside the ".point" element, only the ".edit" is fired.

The downside of delegation with this method is that you need to have css classes on the elements that give you some idea about their function - which might or might not irk you depending on where you stand on design issues. But given jQuery's reliance on css selectors, I think it makes perfect sense.

Check out PinnSpot to see it in action.

Sunday, November 23, 2008

Testing app engine authentication in your unit tests and webtests

If you're into TDD like I am ( I work at ThoughtWorks) you might be trying to test your app engine scripts. And while there are great frameworks that have been adapted to test on the app engine SDK, (there's a link to GAE Unit on my linklist) I wasn't able to find a single one that let you simulate login. So here's a little script that I use.

http://pastie.org/321880

Set the default logged in user to whatever you want... and remember to store a copy of the original users.get_current_user function in your setUp() and replace it back in your tearDown(). Otherwise it'll interfere with your normal server and you'll have to keep restarting it.

Friday, November 21, 2008

PinnSpot is here :D

I've finally gotten round to developing and releasing www.pinnspot.com to the world... Its an idea I've had for years now, but never actually worked much on. I'm glad it's finally seeing the light of day.

It is a work in progress, though, so what I want most now is for people to use it and tell me what they want out of it. I'm trying to listen to everyone I can and make something that's useful to everyone who needs it.

I'm running it on the Google App Engine, btw, and I'm quite happy with the way it works. I'ts been fun writing for it, and much easier than any other platform I've worked on.

Keep watching this space snippets on how it works and what went into it. And go use pinnspot.com :)

Saturday, September 27, 2008

Google App Engine Ahoy!

I'm all pumped about starting on the Google App Engine, and I'm on my way writing the next killer app that I intend to sell for a hundred million dollars, give or take a few. Since I work at ThoughtWorks, there's also TDD involved :D

There's also Textmate involved, so here's the bundles that I'm making up as I go along. Click on the link on the right (Stuff I make box) to get the bundle. Do keep in mind that its a work in progress.

You could also take a look at my github page.

And make sure you try the GAE Unit... it lets you test your app engine programs quite well.