Difference between TextBox.addChangeHandler() and TextBox.addValueChangeHandler()?

615 views
Skip to first unread message

Chris

unread,
Jul 15, 2009, 10:28:40 AM7/15/09
to Google Web Toolkit
Hi

The subject says it all really: Is there a difference between
TextBox.addChangeHandler() and TextBox.addValueChangeHandler(), and if
so, what is it?

The API isn't very clear about this.

Thanks in advance

Chris

Thomas Matthijs

unread,
Jul 15, 2009, 10:34:59 AM7/15/09
to Google-We...@googlegroups.com
> The subject says it all really: Is there a difference between
> TextBox.addChangeHandler() and TextBox.addValueChangeHandler(), and if
> so, what is it?
>
> The API isn't very clear about this.

Look it has source code!

http://google-web-toolkit.googlecode.com/svn/trunk/user/src/com/google/gwt/user/client/ui/TextBoxBase.java

public HandlerRegistration addChangeHandler(ChangeHandler handler) {
return addDomHandler(handler, ChangeEvent.getType());
}


public HandlerRegistration
addValueChangeHandler(ValueChangeHandler<String> handler) {
if (!valueChangeHandlerInitialized) {
valueChangeHandlerInitialized = true;
addChangeHandler(new ChangeHandler() {
public void onChange(ChangeEvent event) {
ValueChangeEvent.fire(TextBoxBase.this, getText());
}
});
}
return addHandler(handler, ValueChangeEvent.getType());
}

Thomas Broyer

unread,
Jul 15, 2009, 12:00:57 PM7/15/09
to Google Web Toolkit


On 15 juil, 16:28, Chris <uk.org.micros...@googlemail.com> wrote:
> Hi
>
> The subject says it all really: Is there a difference between
> TextBox.addChangeHandler() and TextBox.addValueChangeHandler(), and if
> so, what is it?
>
> The API isn't very clear about this.

ValueChangeEvent vs. ChangeEvent: ValueChangeEvent has a getValue()
while with a ChangeEvent you have to cast getSource() to a HasValue
first (and know that getSource() will be a HasValue, or be prepared to
handle the case when it isn't).

this can be a quite important difference in a very "decoupled"
environment; where HasValueChangeHandlers<String> is far more
understandable than HasChangeHandlers (where you'd have to know that
getSource will be a HasValue<String>).

Chris

unread,
Jul 16, 2009, 4:18:52 AM7/16/09
to Google Web Toolkit
Thanks Thomas.

Chris
Reply all
Reply to author
Forward
0 new messages