Hi again,

Tough crowd.... ha ha. I figured out how to fix my problem although
I'm not entirely sure what was wrong with the initial code.

In order to get events firing, I can add the Composite widget instance
to the RootPanel as oppose to appending the widget's root element to
the document body.

So instead of writing this and seeing the interface but not having any
events:

Document.get().getBody().appendChild(myView.getElement());

I can do this instead and events work properly:

RootPanel.get().add(myView);

I'm still interested in knowing why this is the case. I'm pretty sure
the former code was not invented by me but copied from some tutorial
out there.

Tyler

On Sep 21, 12:38 pm, Tyler Cope <[email protected]> wrote:
> Hello,
>
> I'm having trouble getting UiHandler events to fire in a new
> application that I've created with the help of UiBinder.
>
> I've recreated the issue using the most basic code I could come up
> with. Basically, a single button is created with UiBinder xml and the
> widget that is bound to it has a ClickEvent annotation. The app starts
> up, shows a popup message (to ensure that the verification method
> works) and then shows a single lowly button. When the button is
> clicked, I expect that another popup be shown but nothing actually
> happens.
>
> I'm pretty sure this is a case of developer error but I'm not sure
> what I'm missing. I've gone over the UiBinder documentation and the
> HandlerDemo.java sample code and didn't see anything extra or
> different from what I have.
>
> I've also deployed the simple code to AppEngine and tested under
> Chrome, Safari and Firefox. I don't see the alert popup using any of
> the browsers.
>
> http://tcope-testapp.appspot.com/
>
> My environment is as follows:
>
> Eclipse 3.7 Indigo on Mac 10.6.8
> GWT 2.4.0
>
> And the source looks like this:
>
> // TestApp.java
> package com.testapp.client;
>
> import com.google.gwt.core.client.EntryPoint;
> import com.google.gwt.dom.client.Document;
>
> public class TestApp implements EntryPoint {
>
>         public void onModuleLoad() {
>                 MyView myView = new MyView();
>                 Document.get().getBody().appendChild(myView.getElement());
>         }
>
> }
>
> // MyView.ui.xml
> <!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent";>
> <ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
>         xmlns:g="urn:import:com.google.gwt.user.client.ui">
>         <g:HTMLPanel>
>                 <g:Button ui:field="myButton" width="120px" text="Click me" />
>         </g:HTMLPanel>
> </ui:UiBinder>
>
> // MyView.java
> package com.testapp.client;
>
> import com.google.gwt.core.client.GWT;
> import com.google.gwt.event.dom.client.ClickEvent;
> import com.google.gwt.uibinder.client.UiBinder;
> import com.google.gwt.uibinder.client.UiField;
> import com.google.gwt.uibinder.client.UiHandler;
> import com.google.gwt.user.client.Window;
> import com.google.gwt.user.client.ui.Button;
> import com.google.gwt.user.client.ui.Composite;
> import com.google.gwt.user.client.ui.Widget;
>
> public class MyView extends Composite {
>
>         private static MyViewUiBinder uiBinder =
> GWT.create(MyViewUiBinder.class);
>
>         interface MyViewUiBinder extends UiBinder<Widget, MyView> { }
>
>         @UiField Button myButton;
>
>         public MyView() {
>                 initWidget(uiBinder.createAndBindUi(this));
>                 Window.alert("ok press the button...");
>                 System.out.println("after initWidget");
>         }
>
>         @UiHandler("myButton")
>         void handleClick(ClickEvent e) {
>                 Window.alert("Click! [handleClick]");
>                 System.out.println("Click! [handleClick]");
>         }
>
> }
>
> Anyone have any ideas?
>
> Thanks,
>
> Tyler

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to