Thursday, February 7, 2013

Re: Trouble with UiBinder getting UiHandler events to fire under GWT 2.4



Am Freitag, 8. Februar 2013 00:38:37 UTC+1 schrieb Goktug Gokdogan:
FYI, documentation is updated to emphasize that related code sample will not work with widgets.

A bit more should be corrected. The simple Hello World class example is IMHO terrible for starters.

public class HelloWorld {
 
interface MyUiBinder extends UiBinder<DivElement, HelloWorld> {}
 
private static MyUiBinder uiBinder = GWT.create(MyUiBinder.class);

 
@UiField SpanElement nameSpan;

 
public HelloWorld() {
    setElement
(uiBinder.createAndBindUi(this));
 
}

 
public void setName(String name) { nameSpan.setInnerText(name); }

 
public void Element getElement() { return nameSpan; }
}
HelloWorld helloWorld = new HelloWorld();
// Don't forget, this is DOM only; will not work with GWT widgets
Document.get().getBody().appendChild(helloWorld.getElement());
helloWorld
.setName("World");

First, HelloWorld has no super class but uses the (undefined) method setElement() in its constructor. Second, getElement() returns the nameSpan variable and is used in the second code example to append the Hello World UiBinder to the body element. A starter sees code that does not compile and if he assumes that setElement() is maybe the corresponding setter for getElement() { return nameSpan; } then its totally wrong because nameSpan is already assigned via @UiField.

To make things clear getElement() should return the DivElement returned by createAndBindUi() or HelloWorld should extend UiObject and have its getElement() { return nameSpan; } method removed.


-- J.


--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments:

Post a Comment