2017-03-03 50 views
0

我在GWT中有一個TextArea類,但是我的事件處理方法似乎沒有被調用。我定義我的課像這樣:GWT TextArea onBlur沒有被調用

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()); 
    } 

回答

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); 
    } 
}