File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes GWT and the fly likes What is the use of writing XXXEvent.java and XXXEventHandler.java and fire and event? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » GWT
Bookmark "What is the use of writing XXXEvent.java and XXXEventHandler.java and fire and event?" Watch "What is the use of writing XXXEvent.java and XXXEventHandler.java and fire and event?" New topic
Author

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

chaitanya karthikk
Ranch Hand

Joined: Sep 15, 2009
Posts: 800

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.


Love all, trust a few, do wrong to none.
chaitanya karthikk
Ranch Hand

Joined: Sep 15, 2009
Posts: 800

Can anyone please tell me?

Thank you, good day.
chaitanya karthikk
Ranch Hand

Joined: Sep 15, 2009
Posts: 800

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What is the use of writing XXXEvent.java and XXXEventHandler.java and fire and event?
 
Similar Threads
Google Web Toolkit (GWT): Practice
Using FocusWidget.addClickHandler for GWT 2.0 Hyperlink (ClickHandler deprecated)
Does GWT-EXT have a Hyperlink Class? Where is they HyperLink class?
Gin problem
Google Chrome and gwt