GWT FormPanel does not redirect to action URL

183 Views Asked by At

I have an application that uses RequestFactory and UIBinder. The app handles several order processing methods via the RequestFactory before finally sending the results of those requests to the page that tracks the order being complete. The code below is wrapped inside an onSuccess() event from the outer order processing. I only mention that in case it matters.

It is a very simple FormPanel. However, the submit() does not redirect to the URL set by the action attribute. When I watch in my browser's dev tools, I can see that the request was sent successfully to the right URL but the browser does not redirect to that page or show the response from the submission. What am I doing wrong?

                FormPanel form = new FormPanel();
                form.setMethod(FormPanel.METHOD_POST);
                form.setEncoding(FormPanel.ENCODING_URLENCODED);
                form.setAction(System.getProperty(ORDER_COMPLETE_URL));
                form.setHeight("1px");
                form.setWidth("1px");
                form.addStyleName(AppController.HIDDEN_CLASS);

                Hidden transactionId = new Hidden();
                transactionId.getElement().setAttribute("name", "transactionId");
                transactionId.setValue(order.getOrder().getQuoteNumber());

                Hidden transactionTotal = new Hidden();
                transactionTotal.getElement().setAttribute("name", "transactionTotal");
                transactionTotal.setValue(order.getTotalAmount().toString());

                Hidden printURL = new Hidden();
                printURL.getElement().setAttribute("name", "printURL");
                printURL.setValue(order.getPrintURL());

                FlowPanel formStuffer = new FlowPanel();
                formStuffer.add(transactionId);
                formStuffer.add(transactionTotal);
                formStuffer.add(printURL);

                form.add(formStuffer);
                RootPanel.get().add(form);
                form.submit();
2

There are 2 best solutions below

0
Adam On BEST ANSWER

You are using the default constructor: FormPanel form = new FormPanel();

In the documentation you will find this information:

public FormPanel()

Creates a new FormPanel. When created using this constructor, it will be submitted to a hidden <iframe> element, and the results of the submission made available via FormPanel.SubmitCompleteHandler.

Check other constructors and find the one that best suits your requirements.

1
Miniversal On

I finally figured out how to make this happen, thanks to a comment on this post.

The key is to add a target for the form during creation.

FormPanel form = new FormPanel(String target);

You'll want to set the target to be "_self" or "_top" unless you've named your existing window, then use that name.