我在GWT中有一个TextArea类,我已经扩展但是我的事件处理方法似乎都没有被调用。我这样定义了我的课程:
private class MTextBox extends TextArea {
public MTextBox() {
super();
this.addDomHandler(new BlurHandler(){
@Override
public void onBlur(BlurEvent event) {
//Handle Blur
}
}, BlurEvent.getType());
this.addDomHandler(new FocusHandler(){
@Override
public void onFocus(FocusEvent event) {
// Handle Focus.
}
}, FocusEvent.getType());
}
答案 0 :(得分:1)
对我来说似乎很正常,事件被正确触发:
import com.google.gwt.core.shared.GWT;
import com.google.gwt.event.dom.client.BlurEvent;
import com.google.gwt.event.dom.client.BlurHandler;
import com.google.gwt.event.dom.client.FocusEvent;
import com.google.gwt.event.dom.client.FocusHandler;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.TextArea;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.goulds.client.views.ApplicationEntryPoint;
/**
* Entry point classes define <code>onModuleLoad()</code>.
*/
public class TestMTextBox extends ApplicationEntryPoint
{
private class MTextBox extends TextArea {
public MTextBox() {
super();
this.addDomHandler(new BlurHandler(){
@Override
public void onBlur(BlurEvent event) {
//Handle Blur
GWT.log("onBlur");
}
}, BlurEvent.getType());
this.addDomHandler(new FocusHandler(){
@Override
public void onFocus(FocusEvent event) {
// Handle Focus.
GWT.log("onFocus");
}
}, FocusEvent.getType());
}
}
@Override
public void onModuleLoad()
{
VerticalPanel verticalPanel = new VerticalPanel();
verticalPanel.add(new MTextBox());
verticalPanel.add(new MTextBox());
verticalPanel.add(new MTextBox());
RootPanel.get().add(verticalPanel);
}
}