Search code examples
gwtuibinder

How add @UiHandler click of gwt button?


I am gwt2.3 with uibinder.In My application I am made a button and want to add a click handler bu using @UiHandler annotaion.Below is my code: ui.xml

<g:HTMLPanel>
    <g:VerticalPanel>
        <g:HorizontalPanel >
        <g:Button ui:field="btnAccessLevel" text="Access Level" styleName="submit" />
        <g:Button ui:field="btnSave" text="Save" styleName= "submit" />
        </g:HorizontalPanel>
        <g:AbsolutePanel ui:field="formPanel">
        </g:AbsolutePanel>
        <g:AbsolutePanel ui:field="accessLevelPanel">
        </g:AbsolutePanel>
    </g:VerticalPanel>
</g:HTMLPanel>

.java

    @UiField
Button btnAccessLevel;


@Inject
public DocumentFormView(final Binder binder) {
    widget = binder.createAndBindUi(this);
     @UiHandler("btnAccessLevel")
     void handleClick(ClickEvent e) {
        Window.alert("Hello, AJAX");
      }
}

When I am trying this I am getting this error: void is an invalid type for the variable handleClick I am not getting what issue is.Please help me out. Thanks in advance.


Solution

  • Your code is not legal Java - move the function declaration outside of the constructor.

    Otherwise, your syntax for @UiHandler is correct!