Hi Ajay, A common reason for using a single event listener across many links/ buttons etc is performance. See:
http://code.google.com/docreader/#p=google-web-toolkit-doc-1-5&s=google-web-toolkit-doc-1-5&t=FAQ_UIUseOneListener As Danox says, there is no one best approach, it depends on the application type and size. The main issues are encapsulation, decoupling, and granularity. A good unit of granularity is, say, a Composite panel that performs a main task in your UI and may have several widgets inside it including a number of links/buttons. Within the Composite all the buttons/links etc are visible, so a single ClickListener instance can service them all, e.g. { public void onClick(Widget sender) { if (sender==b1) { doSomething(..) else if (sender==b2) { changeListeners.fireChange(..); ......// etc } Technically you can make a second main Composite component implement ClickListener and register it with a button buried in Composite 1. I think that is probably a bit too fine grained and involves Composite 2 knowing about Composite 1 internals (breaks encapsulation). I prefer to implement events visible to other main components at the Composite level. So Composite 2 registers with Composite 1, and Composite 1 mediates between Composite 2 and the button concerned. regards gregor On Jan 30, 6:15 am, Ajay Garg <[email protected]> wrote: > Thanks danox for your viewpoint. > > However, just curious, isn't case 2 doable as a case 1; i.e. after the > button is clicked, it calls a method elsewhere, which may then > delegate to a RPC ... > > Ajay Garg > > On Jan 30, 10:14 am, danox <[email protected]> wrote: > > > I'm not sure that there is a recommended way. Its really up to you or > > the coding style of your team. > > > I tend to use 1. for most simple implementations (e.g. if I want a > > button click to call a method elsewhere) and 2. for more complex > > implementations (e.g. if I am adding a series of buttons > > programmatically, each of which will trigger an RPC call with unique > > parameters when clicked). > > > I've never used 3 and it doesn't strike me as a great way to do it, > > but that's just me. > > > On Jan 30, 3:38 pm, Ajay Garg <[email protected]> wrote: > > > > Right, and so that brings to the query in my first post :: What is the > > > recommended way to attach a clicklistener to simple widgets like > > > Button and Hyperlink :: > > > > 1. Let a Button be listened by itself ? > > > 2. Let a Button be listened by a bigger widget (eg. DeckPanel, > > > HorizontalPanel ..) encapsulating it? > > > 3. Let a Button be listened by the module of which it is a part? > > > > Ajay Garg > > > > On Jan 30, 9:08 am, ajay jetti <[email protected]> wrote: > > > > > The Answer to second question depends on the scenario , but multiple > > > > listners on a single button? i din know if that is possible- Hide > > > > quoted text - > > > - Show quoted text - --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/Google-Web-Toolkit?hl=en -~----------~----~----~----~------~----~------~--~---
