0

I've been trying to write contacts. example using gwt-platform I've successfully got the contacts view using manual reveal to obtain contacts list, I'm trying to use UiHandlers for add button but it is not calling the method in my ContactsPresenter's onAddButtonClicked().

fallowing is the code snippet of my view

public class ContactsView extends ViewWithUiHandlers<ContactsViewUiHandlers> implements  ContactsPresenter.MyView {

private final Widget widget;

@UiField
Button addButton;

@UiHandler("addButton")
public void onAddButtonClick(ClickEvent e){
    System.out.println("add button clicked");
    getUiHandlers().onAddButtonClicked();
}  

}

fallowing is UiHandlers interface

public interface ContactsViewUiHandlers extends UiHandlers{
        void onAddButtonClicked();
}

and in my presenter i'm firing an event with event bus in onAddButtonClicked().

but the control is not coming to my presenter and i'm getting the following exception when i'm clicking the add button.

[ERROR] [contactsgwtp] - Uncaught exception escaped

10:17:10.527 [ERROR] [contactsgwtp] Uncaught exception escaped

com.google.gwt.event.shared.UmbrellaException: One or more exceptions caught, see full set in UmbrellaException#getCauses
    at com.google.gwt.event.shared.HandlerManager.fireEvent(HandlerManager.java:129)
    at com.google.gwt.user.client.ui.Widget.fireEvent(Widget.java:129)
    at com.google.gwt.event.dom.client.DomEvent.fireNativeEvent(DomEvent.java:116)
    at com.google.gwt.user.client.ui.Widget.onBrowserEvent(Widget.java:177)
    at com.google.gwt.user.client.DOM.dispatchEventImpl(DOM.java:1351)
    at com.google.gwt.user.client.DOM.dispatchEvent(DOM.java:1307)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
    at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
    at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
    at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:337)
    at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:218)
    at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
    at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561)
    at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:269)
    at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
    at com.google.gwt.core.client.impl.Impl.apply(Impl.java)
    at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:213)
    at sun.reflect.GeneratedMethodAccessor28.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
    at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
    at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
    at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:292)
    at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:546)
    at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:363)
    at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.NullPointerException: null
    at com.saik.in.client.core.ContactsView.onAddButtonClick(ContactsView.java:51)
    at com.saik.in.client.core.ContactsView_BinderImpl$1.onClick(ContactsView_BinderImpl.java:50)
    at com.google.gwt.event.dom.client.ClickEvent.dispatch(ClickEvent.java:54)
    at com.google.gwt.event.dom.client.ClickEvent.dispatch(ClickEvent.java:1)
    at com.google.gwt.event.shared.GwtEvent.dispatch(GwtEvent.java:1)
    at com.google.web.bindery.event.shared.EventBus.dispatchEvent(EventBus.java:40)
    at com.google.web.bindery.event.shared.SimpleEventBus.doFire(SimpleEventBus.java:193)
    at com.google.web.bindery.event.shared.SimpleEventBus.fireEvent(SimpleEventBus.java:88)
    at com.google.gwt.event.shared.HandlerManager.fireEvent(HandlerManager.java:127)
    at com.google.gwt.user.client.ui.Widget.fireEvent(Widget.java:129)
    at com.google.gwt.event.dom.client.DomEvent.fireNativeEvent(DomEvent.java:116)
    at com.google.gwt.user.client.ui.Widget.onBrowserEvent(Widget.java:177)
    at com.google.gwt.user.client.DOM.dispatchEventImpl(DOM.java:1351)
    at com.google.gwt.user.client.DOM.dispatchEvent(DOM.java:1307)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
    at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
    at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
    at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:337)
    at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:218)
    at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
    at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561)
    at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:269)
    at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
    at com.google.gwt.core.client.impl.Impl.apply(Impl.java)
    at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:213)
    at sun.reflect.GeneratedMethodAccessor28.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
    at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
    at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
    at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:292)
    at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:546)
    at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:363)
    at java.lang.Thread.run(Thread.java:662)

any suggestions on what i'm missing, thanks in advance

Anders R. Bystrup
  • 15,729
  • 10
  • 59
  • 55
SKM
  • 71
  • 1
  • 10
  • What is line no. 51 in ContactsView? Show your Presenter's code. – RAS Nov 01 '12 at 06:35
  • @RAS line no. 51 is getUiHandlers().onAddButtonClicked(); and in presenter i have public void onAddButtonClicked() { fireEvent(new AddContactEvent()); } – SKM Nov 01 '12 at 09:19

2 Answers2

3

Obviously getUiHandlers() is null... But you knew that :-)

I would expect the cause of this could be that you have forgotten to set the UI handlers when injecting in the associated presenter (which would be the normal procedure in GWTP) - something like:

public class ContactsPresenter extends Presenter<ContactsPresenter.MyView, ContactsPresenter.MyProxy> 
                               implements ContactsViewUiHandlers 
{
    public interface MyView extends View, HasUiHandlers { /* nothing */ }

    private PlaceManager placeManager;

    @Inject
    ContactsPresenter( final EventBus eventBus , final MyView view , 
                       final MyProxy proxy , final PlaceManager placeManager )
    {
        super( eventBus , view , proxy );
        this.placeManager = placeManager;
        getView().setUiHandlers( this );
    }
    ...

    @Override
    public void onAddButtonClicked()
    {
        placeManager.revealPlace( new PlaceRequest( "somewhereovertheocean" ) );
    }
    ...
}

(The operative part being getView().setUiHandlers( this ); and implements ContactsViewUiHandlers).

Incidentally, it is good practice to always check getUiHandlers() for null-ness before invoking any methods on it...

Hope that helps.

Cheers,

Anders R. Bystrup
  • 15,729
  • 10
  • 59
  • 55
  • thanks that was the mistake, will you please tell me how can i move to a new place EditContactsView should reveal when i click on add button,and will you please give any link that will help in using gwt platform framework efficiently. – SKM Nov 02 '12 at 05:23
  • I suggest that you also `@Inject` your `PlaceMaanager` in the `Presenter` and use that for navigation - I have edited my answer to outline that. – Anders R. Bystrup Nov 02 '12 at 08:41
  • got some error while revealing EditContactsView, i tried using simply a html panel then my view is opening but when i've added the following code – SKM Nov 05 '12 at 17:40
  • it is giving Caused by: java.lang.UnsupportedOperationException: This panel does not support no-arg add() at com.google.gwt.user.client.ui.Panel.add(Panel.java:66) i'm using a decorator panel to which i'm adding a vertical panel and a horizontal panel – SKM Nov 05 '12 at 17:45
1

Looking at the exception you've provided I think you have missed one of the following points :

  1. ContactsPresenter should implement ContactsViewUiHandlers like this: ContactsPresenter implemets ContactsViewUiHandlers
  2. Set ContactsPresenter's reference as contactsView.UIHandlers like this: getView().setUiHandlers(this);

After doing both the things you should not get the mentioned Exception. I hope this helps you.

RAS
  • 8,100
  • 16
  • 64
  • 86
  • thanks that is it, i didn't added setUiHandlers() in my presenter. – SKM Nov 02 '12 at 06:08
  • Good to know that. If this is answer is helpful to you, then why don't you accept it? – RAS Nov 02 '12 at 06:16
  • i think i can't accept two answers but both of you gave same answer thanks again for answer – SKM Nov 05 '12 at 17:31