2015-02-17 118 views
1

我正在爲gwt項目使用gwt和gwtbootstrap3。我的代碼看起來像使用gwt和gwtbootstrap3提交表單而不刷新頁面

<b:NavbarForm pull="LEFT"> 
     <b:TextBox placeholder="Search" addStyleNames="col-lg-8"/> 
    </b:NavbarForm> 

現在,如果我在文本框中鍵入任何東西,按下回車鍵,GWT是重裝整個頁面,我不想要的,所有我想要的是得到從文本框中的值,並調用方法。有什麼辦法可以實現嗎?

僅供參考,如果我不使用NavbarForm,但我不能使搜索框內聯,我可以取值。

http://gwtbootstrap3.github.io/gwtbootstrap3-demo/#navbar

僅供參考,只是如果我換行的文本框中像NavbarText或NavbarNav的UI一些其它容器的更新被損壞。

回答

1

這可能是gwtbootstrap3中的一個錯誤 - 他們最近做了一個Form小部件的修改。

但現在,你可以添加一個SubmitHandlerNavbarForm並取消SubmitEvent以防止它重新加載頁面:

navbarForm.addSubmitHandler(new SubmitHandler() { 
    @Override 
    public void onSubmit(SubmitEvent event) { 
     event.cancel(); 
    } 
}); 

當使用UiBinder的:

@UiHandler("navbarForm") 
void onNavbarSubmit(SubmitEvent event) { 
    event.cancel(); 
} 

注意,在這個案例SubmitEvent屬於org.gwtbootstrap3.client.ui.base.form.AbstractForm.SubmitEvent,而非com.google.gwt.user.client.ui.FormPanel.SubmitEvent

+0

我正在使用UiBinder,當我嘗試添加@UiHandler(「navbarForm」)時,它給了我錯誤[[錯誤]字段'navbarForm'沒有'addFormPanel.SubmitHandler'關聯的方法。 – Ashish 2015-02-18 14:59:28

+0

@Ashish:請參閱我更新的答案。 – 2015-02-18 20:40:13

+0

感謝您的回覆,但我找不到'org.gwtbootstrap3.client.ui.base.form.AbstractForm.SubmitEvent'類,我在我的課程路徑中有gwtbootstrap3-0.8.1.jar' – Ashish 2015-02-18 21:45:29