GWT simple web form submit - redirect to new page

白昼怎懂夜的黑 提交于 2019-12-21 18:04:28

问题


I have a simple web form written in Google web toolkit. I want the user to follow a new URL when he clicks on the submit button. However I cannot find any examples of redirecting the user to a new URL from within GWT code. How may I achieve this?


回答1:


To redirect the user to a new page, use Window.Location.assign().

To have this happen when the user submits the form, use FormPanel.addSubmitHandler() , or addSubmitCompleteHandler() to have the redirect happen when the form submission is complete.




回答2:


the exact answer is:

    form.getElement().<FormElement>cast().setTarget("");

by this line you changing the target parameter of the form and now the main page redirected to the action url.

be careful that Window.Location.assign() makes a new GET request after your main POST request!, So it is not the answer.




回答3:


So actually what you need to do is to use the setAction() method of the FormPanel AND you need to construct the form panel as such:

FormPanel form = new FormPanel(new NamedFrame("_self"));

This will make the submit redirect as usual.

Hope this helps.




回答4:


You can have a look at example at roughain http://examples.roughian.com/index.htm#Panels~FormPanel

Also you can read javadoc @http://google-web-toolkit.googlecode.com/svn/javadoc/1.6/com/google/gwt/user/client/ui/FormPanel.html

To make user go to a url use setAction method of FormPanel



来源:https://stackoverflow.com/questions/4062104/gwt-simple-web-form-submit-redirect-to-new-page

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!