2015-02-17 60 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