LDSTechForumProjects

Beyond MVP Lab 1

Use the EventBus to Populate a status bar at the bottom of the contacts application

  1. Checkout the following as a maven project: https://gibb.myversioncontrol.com/subversion/mvp_contacts/tags/1.3.eventbus-lab/ (user/pass: training/training)
    1. add Google->Web Toolkit Settings, check "Use Google Web Toolkit"
    2. goto Google->Web Application, check "This project has a war directory" - select src/main/webapp
  2. You will
    1. Create a StatusUpdateEvent
    2. Create a StatusUpdateEventHandler
    3. Fire at least one StatusUpdateEvent where work is performed (Such as saving, deleting or listing the contacts
    4. Register a StatusUpdateEventHandler that updates the status bar
    5. All this will be done in the contacts-web project

Fix Errors

  1. In Contacts.gwt.xml change
  <source path='client'/>

to

  <source path='client'>
    <exclude name="**/*Test.java" />
  </source>

and delete

  <set-property name="user.agent" value="gecko,gecko1_8" />

Create a StatusUpdateEventHandler interface

  1. In the com.google.gwt.sample.contacts.client.event package create StatusUpdateEventHandler interface that extends com.google.gwt.event.shared.EventHandler
  2. it should have one method that takes a StatusUpdateEvent (which you will create next), the method name should be something like onStatusUpdate

Create a StatusUpdateEvent class

  1. The easiest way is to copy one of the other events :-)
  2. it must extend GwtEvent<StatusUpdateEventHandler>
  3. there must be a public static TYPE variable of Type<StatusUpdateEventHandler>
  4. the dispatch method must be overridden and the handler's onStatusUpdate method called
  5. The class must have a String field to hold the status, set by the constructor along with a getter

Fire at least one StatusUpdateEvent

  1. Open EditContactPresenter.java
  2. in one of the onSuccess methods add (The status can be whatever you want)
eventBus.fireEvent(new StatusUpdateEvent("Saved "+result.getContactDto().getId()));


Register a StatusUpdateEventHandler

  1. Open AppController.java
  2. in the bind method add a handler of StatusUpdateEventHandler similar to the others done there
  3. the method body of the handler should call display.setStatus and pass the status string from the event


Run the project

  1. Add contacts-web to LDS Tech Server under Servers tab
  2. Run the server
  3. Create a new web application run configuration
  4. Under the Server tab, uncheck "Run built-in server"
  5. Under the GWT tab, enter "/contacts" in URL
  6. This should be the URL http://localhost:8080/contacts/?gwt.codesvr=127.0.0.1:9997
  7. Ignore any errors about EditPresenterTest.java
This page was last modified on 11 June 2010, at 08:20.

Note: Content found in this wiki may not always reflect official Church information. See Terms of Use.