GWT Formal Panel Does Not Call onSubmitComplete

GWT: I can call the servlet in the browser. When I call it in form, it can call onSubmit. But it does not call onSubmitComplete. This will also open a new window, uri is my servlet.

String URL= GWT.getModuleBaseURL()+"getType"; FormPanel formPanel = new FormPanel(); formPanel.setAction(URL); formPanel.setEncoding(FormPanel.ENCODING_URLENCODED); formPanel.setMethod(FormPanel.METHOD_GET); formPanel.addSubmitHandler(new SubmitHandler(){ @Override public void onSubmit(SubmitEvent event) { // TODO Auto-generated method stub System.out.println(event.getSource()); } }); formPanel.addSubmitCompleteHandler(new FormPanel.SubmitCompleteHandler() { public void onSubmitComplete(SubmitCompleteEvent event) { System.out.println("in"); System.out.println(event.getResults()); } }); formPanel.submit(); GWT.xml <servlet class="msp2.server.getType" path="/getType" /> web.xml <servlet > <servlet-name>getType</servlet-name> <servlet-class>msp2.server.getType</servlet-class> </servlet> <servlet-mapping> <servlet-name>getType</servlet-name> <url-pattern>/msp2_app/getType</url-pattern> </servlet-mapping> 
+4
source share
6 answers

I know this is an old question, but I had the same problem and none of these answers was a solution. After calling FormPanel.submit() response will open in a new tab and onSubmitComplete() will not be called.

As a result, it turned out that my FormPanel not added to my dialog box called submit() . Since the whole form consists of Hidden fields whose values ​​are set depending on the button on the page that was clicked, my FormPanel actually does not contain form widgets with user-selectable values, so I didn’t need to add it to the window anywhere.

This is what caused the response to open in a new window and onSubmitComplete() not called. I added it to the panel for my DialogBox and after that it worked as it should.

+3
source

From javadoc :

The server server is expected to respond with the content type "text / html", which means that the returned text will be treated as HTML. If any other type of content is specified by the server, then the HTML result sent in the onFormSubmit event will be unpredictable in different browsers, and the onSubmitComplete event may not fire at all.

If you say that the answer opens in another window and you have not set a specific goal for your FormPanel , it will probably happen if your server does not response.setContentType("text/html") (or similar with ;charset= )

+2
source

I fought through

It will also display a new window.

All the answers I found related to adding a form widget to the panel or adding the FormPanel itself instead of the widget, which makes the action link absolute and other things that did not gel. The solution that REALLY WORKS for me after an hour of trying was reading javadoc

  public FormPanel(String target) {...} 

@param specify the name <iframe> to get the results or null to indicate that the current page should be replaced with

Just pass "_self" to the FormPanel constructor

 FormPanel form = new FormPanel("_self"); 

Or set the .setTarget (...) method later. Whoa - it does not open a pop-up window (which will probably be blocked by Chrome). Also, creating a form in a method and submitting it without adding a DOM works as expected.

+1
source

onSubmitComplete will be called if the form submission completes successfully. Make sure that there are no errors when submitting the form.

Submit the code you are trying. This will help others sort out the problem.

You can also try an example using FormPanel provided here

0
source

I also had the same problem, as it turned out, I did not set the URL of the FormPanel action.

 final FormPanel formPanel = new FormPanel(); formPanel.setAction("/test"); 
0
source

The problem arises from the frames that are used in the GWT application. Often, during file uploads, cross-calls inside Javascript are often used, which are not allowed. During application development, you open development mode, that is, on port 9999, so your browser uses http://127.0.0.1:9999/YourApp.html . The servlet that should process the downloaded file runs on another computer or on the same computer, but on a different port (i.e. http://127.0.0.1:6544/servlet/upload ). Both cases fall into the Javascript security issue because the port number is included in the domain.

But you can install Apache on your development machine and use mod_proxy to move both parts of your application to the same domain. Set -bindAddress to localhost and use the static port (i.e. 9999) for your GWT application. Also run the servlet on the local host with a static port (i.e. 6544). Then you can add

 ProxyRequests Off ProxyPreserveHost Off ProxyTimeout 3600 <Location /gui> Allow from All ProxyPass http://localhost:9999 ProxyPassReverse http://localhost:9999 </Location> <Location /api> Allow from All ProxyPass http://localhost:6544/servlet ProxyPassReverse http://localhost:6544/servlet </Location> 

for your apache configuration. Now you can start the GWT application using http: //localhost/gui/YourApp.html "and refer to" / api / upload "(relative Url) in FormPanel.setAction (). Now both domains (GWT application and upload-servlet) are within the same domain ( http: // localhost ) and you will get SubmitCompleteEvent.getResults (). Inside the servlet, you should also set the “Content-Type” HTTP response header to “text / html”.

0
source

Source: https://habr.com/ru/post/1442207/


All Articles