Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

uiBinder on Button Clickevent

I'm trying to use uiBinder. I followed the tutorial provided by google, but I don't know why clickevent doesn't work? I want to count number of clicks and show it in the span, it doesn't work, I also put window.alert but it seems that the event handler is not called at all! Can anyone help me? It's couple of hours I'm working on it but can't find the problem!

Thank you so much

P.S. Below is my code


<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
   xmlns:g="urn:import:com.google.gwt.user.client.ui">
   <ui:style>
   </ui:style>
   <g:HTMLPanel>
    <table>
        <tr>
            <td><img ui:field='imgPrd'/></td>
            <td>
               <span ui:field='lblNum'></span>
                <g:Button ui:field='btnAdd'></g:Button>
            </td>
        </tr>
    </table>
   </g:HTMLPanel>


public class uiProductList extends Composite {

@UiField Button btnAdd;
@UiField ImageElement imgPrd;
@UiField SpanElement lblNum;

int count;
private static uiProductListUiBinder uiBinder =
GWT.create(uiProductListUiBinder.class);

interface uiProductListUiBinder extends UiBinder<Widget,
uiProductList> {
}

public uiProductList() {
   initWidget(uiBinder.createAndBindUi(this));
}


@UiHandler("btnAdd")
void handleClick(ClickEvent e) {
  Window.alert("test");
  count++;       
  lblNum.setInnerText(Integer.toString(count));
 }

}
like image 884
Marjan Avatar asked Jun 27 '10 01:06

Marjan


2 Answers

You should correctly add your widget to the root panel. Use

RootPanel.get().add(uiProduct);

Otherwise the handlers are not initialized.

like image 112
Hilbrand Bouwkamp Avatar answered Nov 09 '22 17:11

Hilbrand Bouwkamp


I had exactly the same problem and here is the conclusion:

RootPanel.getBodyElement().appendChild(uiProduct.getElement()); - NOT WORKING

RootPanel.get().add(uiProduct); - WORKING FINE

like image 37
Саша Гајић Avatar answered Nov 09 '22 18:11

Саша Гајић