A: 

Not sure if thats the best way to write a client side listener.

I would suggest using AJAX, in that way you make all your work on the server side, and an Ajax component keeps polling the data from the server.

medopal
Actually I am using Ajax here in the way I am filling up the div with the messages that I receive. As for polling for data - the API that I'm using does not support that, which makes sense to me, as when you're connected to a IM server, you are the one that gets the messages. But maybe I misunderstood you, can you be more concrete?
Andrei
I agree with medopal and go with an AJAX solution, creating a separate page to act as a service which is polled using JavaScript function from setTimeout(). Whenever polled I would have the page return a JOSN object with the last records up to a given ID or timestamp for an elegant and robust solution. Unfortunately you are stuck with polling in practice as keeping a streaming connection open in JS is not really practical (technically possible, but requires advanced ninja skills to implement in a robust way due to varying browser/proxy/web filter software timeout limits).
Iain Collins
The polling practice is indeed the bottleneck to a good approach. But will keep in mind the JSON way of doing it though. Thanks anyway.
Andrei
A: 

A small note on your problem description: your Listener don't have to be a inner class. (But that might not help you at all)

Rickard von Essen
Hmm, how can you go around implementing the PacketListener[1] interface then?[1]http://www.igniterealtime.org/builds/smack/docs/latest/javadoc/org/jivesoftware/smack/PacketListener.html
Andrei
A: 

Take a look at Comet. Maybe it can help or at least give you some ideas. Check the Implementations and Alternatives sections.

Cheers

lunohodov