uiBinder on Button Clickevent
Asked Answered
R

2

5

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));
 }

}
Ressieressler answered 27/6, 2010 at 1:38 Comment(2)
Does the code work if you add a click handler the "regular" way, with addClickHandler()?Jeroboam
Are you sure you're closing the <ui:UiBinder> tag? It seems to be missing in the above code.Mazman
I
6

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

RootPanel.get().add(uiProduct);

Otherwise the handlers are not initialized.

Idocrase answered 27/6, 2010 at 11:41 Comment(0)
A
2

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

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

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

Ause answered 10/2, 2011 at 9:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.