开发者

uiBinder on Button Clickevent

开发者 https://www.devze.com 2023-01-05 01:22 出处:网络
I\'m trying to use uiBinder. I followed the tutorial provided by google, but I don\'t know why clickevent doesn\'t work? I w开发者_JAVA百科ant to count number of clicks and show it in the span, it doe

I'm trying to use uiBinder. I followed the tutorial provided by google, but I don't know why clickevent doesn't work? I w开发者_JAVA百科ant 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));
 }

}


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

RootPanel.get().add(uiProduct);

Otherwise the handlers are not initialized.


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

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

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

0

精彩评论

暂无评论...
验证码 换一张
取 消