UI and Navigator with Form Submission

Hi everyone,

I have been struggling for couple of days now on integrating a Window with Form submission (JavascriptComponent or FormSender) towards a 3rd party URL and on CallBack response to close the Window and navigate from the current page towards on new page.

I traced the HTTP req/resp everything seems fine and debug, it looks like everything is fine from the RequestHandler on the 3rd party URL and the UI (exception NPE on UI.getCurrent() , I had to pass getUI() instead to the CallBack request handler).

But visually the Window does not close and the page does not change, and as soon as I click on close cross of the Window the new page load (@PreserveOnRefresh) with the correct content and old page gone.

I tried many setting either from the Form action (“”, “/newPage”, “/curPage”) with or without target (_top, _self, _parent, none)… method change POST to GET but still all same behavior !?

Any help will be graceful.

On the Window, I have the form with JavascriptComponent:

com_vaadin_ComponentJs = function() {

var me = this;

var makeFromTag = function(state) {
    var formEl = document.createElement("form");
    formEl.setAttribute("id", "formID");

// formEl.setAttribute(“action”, “/newPage”);
formEl.setAttribute(“action”, “”);
formEl.setAttribute(“method”, “POST”);
// formEl.setAttribute(“method”, “GET”);
// formEl.setAttribute(“target”, “_self”);
formEl.setAttribute(“target”, “_parent”);
return formEl;

var makeDivTag = function() {
    var pDiv = document.createElement("div");
    pDiv.setAttribute("id", "container");
    return pDiv;

var makeInputTag = function() {
    var submit = document.createElement("input");
    submit.setAttribute("class", "btn");
    submit.setAttribute("type", "submit");
    submit.setAttribute("name", "btn");
    submit.setAttribute("value", "Get Info");
    return submit;

[/code]Then on the attach() of the Window I add the request handler callback:

private MyRequestHandler addCallbackHandler() { callbackHandler = new MyCBRequestHandler(getUI(), this); getSession().addRequestHandler(callbackHandler); return callbackHandler; } On the request Call back handler :

    public boolean handleRequest(VaadinSession session, VaadinRequest request,
            VaadinResponse response) throws IOException {

    String queryStr = "token=xxx";
    ((WebUI) ui).uriFragmentChanged(new UriFragmentChangedEvent(ui.getPage(), newPage.getUrigrament()));
    ((WebUI)ui).getNavigator().navigateTo(newPage.getUrigrament() + queryStr);
    cleanUpSession(session); // Runnable with : session.removeRequestHandler(MyCBRequestHandler.this);

The WARNING when I close the Window not programaticaly:
Aug 02, 2016 10:41:26 PM com.vaadin.server.communication.ServerRpcHandler parseInvocation
WARNING: RPC call to v.v received for connector 290 but no such connector could be found. Resynchronizing client.

It seems I cannot programaticaly close the Window (I tried on reponse Callback to include JS to close the window , or as argument as mentioned above: myWindow.close():wink: does not work at all…

So in request handler you just need to redirect the browser to a new url?
If this is the case maybe you can simply set Location header on response

public boolean handleRequest(VaadinSession session, VaadinRequest request,
                                                      VaadinResponse response) throws IOException {
    String queryStr = "token=xxx";
    cleanUpSession(session); // Runnable with : session.removeRequestHandler(MyCBRequestHandler.this);
     response.setHeader("Location", newPageUrl);
    return true;


Hi Marco,

Thank you for your reply :slight_smile:

I actually tried that but I forgot to set the status 302… I will try that way. Adding the myWindow.close() within the Runnable on the cleanupSesssion after removing the requestHandler seems to works closing the window but the navigation is still erratic with either blank page with POST request stale…

The Location solution does the job but I got back to the UI.getCurrent() NPE on the enter method, the stack vaadin:
com.myapp.ui.View.enter… NPE
com.vaadin.ui.UI.doInit(UI.java:646) com.vaadin.server.communication.UIInitHandler.getBrowserDetailsUI(UIInitHandler.java:222) com.vaadin.server.communication.UIInitHandler.synchronizedHandleRequest(UIInitHandler.java:74) com.vaadin.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:41) com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1401) com.vaadin.server.VaadinServlet.service(VaadinServlet.java:237)

Potentially I may reiniatialize the Vaadin Session on setCurrent on getUI() ?

My last statement actually resolve the issue thks :wink: