This week's book giveaway is in the Artificial Intelligence forum.
We're giving away four copies of Pragmatic AI and have Noah Gift on-line!
See this thread for details.
Win a copy of Pragmatic AI this week in the Artificial Intelligence forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

What is the use of writing XXXEvent.java and XXXEventHandler.java and fire and event?  RSS feed

 
Ranch Hand
Posts: 806
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all, I am new to GWT and I am looking into MVP1 architecture. I am learning from GWT documentation. I am going though the Contacts application.

I understood the flow and the need of having Presenter, View and AppController. But the thing which I dint understood is what is the need for having the Event classes and EventHandler classes under com.google.gwt.sample.contacts.client.event package?

For instance we can consider this code snippet from ContactsPresenter.javaWhen I click on Add button, new AddContactEvent() is being initialized. Already we binded this event with a event handler in AppController like thisthen addNewContact() method is called in which we are simply changing the History like thisWhat I don't understand is instead of writing all this code I can simply change the history from presenter method itself like thisWhy Should I use events and handlers approach instead?

On asking to one of my friends, he said that some times we might want to do some initialization before the view is actually loaded, there is a common central place(AppContoller) for every presenter to communicate. But I am not convinced with the answer.

Can anyone please shed some light and make it clear.

Thank you all, good day.
 
chaitanya karthikk
Ranch Hand
Posts: 806
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone please tell me?

Thank you, good day.
 
chaitanya karthikk
Ranch Hand
Posts: 806
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all, I think I understood why we need to use an XXXEvent class and XXXEventHandler class. I'll put my understanding and anyone please tell me whether I am right or not.

I understood that if at all I want to change the view from a Presenter I have to use event bus and fire an event, this initializes a handler which is written in AppContoller.

Firing events is only used when we have to change the view from a Presenter. We can directly change the History from Presenter as I discussed in this post, but the point is if we want to execute some business logic each time a particular view is loaded, then in each Presenter I have to write the same code. This is a repetitive process.

Having event bus and firing the event will initialize the handler written in some central place, in our case it is the AppController. Now I can simply write the business logic in a method in AppController class and call it each time the handler is invoked.

This is what I understood after writing a sample application on my own and after discussing with friends.

Is my understanding right?

Thank you all in advance, good day.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!