Example usage for com.google.gwt.http.client RequestBuilder POST

List of usage examples for com.google.gwt.http.client RequestBuilder POST

Introduction

In this page you can find the example usage for com.google.gwt.http.client RequestBuilder POST.

Prototype

Method POST

To view the source code for com.google.gwt.http.client RequestBuilder POST.

Click Source Link

Document

Specifies that the HTTP POST method should be used.

Usage

From source file:org.openxdata.designer.client.controller.FormDesignerController.java

public void saveLocaleText(String languageXml) {
    String url = FormUtil.getHostPageBaseURL();
    url += FormUtil.getFormDefUploadUrlSuffix();
    url += FormUtil.getFormIdName() + "=" + this.formId;
    url += "&localeXml=true";

    RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL.encode(url));

    try {/*from www .  j ava  2s  . c  o m*/
        builder.sendRequest(languageXml, new RequestCallback() {
            public void onResponseReceived(Request request, Response response) {

                if (response.getStatusCode() != Response.SC_OK) {
                    FormUtil.displayReponseError(response);
                    return;
                }

                FormUtil.dlg.hide();
                Window.alert(messages.formSaveSuccess());
            }

            public void onError(Request request, Throwable exception) {
                FormUtil.displayException(exception);
            }
        });
    } catch (RequestException ex) {
        FormUtil.displayException(ex);
    }
}

From source file:org.openxdata.runner.client.controller.FormRunnerController.java

public void onSubmit(String xml) {

    FormUtil.dlg.setText(i18n.submitting());
    FormUtil.dlg.center();/*  www .  j  a  v a  2 s.  com*/

    final String submitXml = xml;

    Scheduler.get().scheduleDeferred(new ScheduledCommand() {
        public void execute() {
            String url = FormUtil.getHostPageBaseURL();
            url += FormUtil.getFormDataUploadUrlSuffix();

            RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL.encode(url));

            try {
                builder.sendRequest(submitXml, new RequestCallback() {
                    public void onResponseReceived(Request request, Response response) {
                        FormUtil.dlg.hide();

                        if (response.getStatusCode() != Response.SC_OK) {
                            FormUtil.displayReponseError(response);
                            return;
                        }

                        if (response.getStatusCode() == Response.SC_OK) {
                            if (FormUtil.showSubmitSuccessMsg())
                                Window.alert(i18n.formSubmitSuccess());

                            String url = FormUtil.getHostPageBaseURL();
                            url += FormUtil.getAfterSubmitUrlSuffix();

                            if (FormUtil.appendEntityIdAfterSubmit()) {
                                url += FormUtil.getEntityIdName();
                                if (entityId > 0)
                                    url += "=" + entityId;
                                else if (entityId == 0 && response.getText().trim().length() > 0)
                                    url += "=" + response.getText();
                            }

                            Window.Location.replace(url);
                        } else
                            FormUtil.displayReponseError(response);
                    }

                    public void onError(Request request, Throwable exception) {
                        FormUtil.displayException(exception);
                    }
                });
            } catch (RequestException ex) {
                FormUtil.displayException(ex);
            }
        }
    });
}

From source file:org.otalo.ao.client.JSONRequest.java

License:Apache License

public void doPost(String fetchURL, String postData, JSONRequester requester) {
    this.requester = requester;
    // RequestBuilder used to issue HTTP GET requests.
    RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.POST, URL.encode(BASE_URL + fetchURL));
    requestBuilder.setHeader("Content-Type", "application/x-www-form-urlencoded");
    try {//from ww w  . ja  v  a2 s  .  co m
        requestBuilder.sendRequest(postData, new JSONResponseTextHandler());
    } catch (RequestException ex) {
        // TODO
    }
}

From source file:org.otalo.ao.client.JSONRequest.java

License:Apache License

public static void doPost(String url, String postData) {
    RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, url);

    try {// w ww. j a v  a  2s . co m
        builder.setHeader("Content-Type", "application/x-www-form-urlencoded");
        Request response = builder.sendRequest(postData, new RequestCallback() {

            public void onError(Request request, Throwable exception) {
                // code omitted for clarity
            }

            public void onResponseReceived(Request request, Response response) {
                // code omitted for clarity
            }
        });
    } catch (RequestException e) {
    }
}

From source file:org.overlord.gadgets.web.client.presenter.LoginPresenter.java

License:Open Source License

public void authenticateUser(String username, String password, RestfulInvoker.Response callback) {

    JSONObject postData = new JSONObject();
    postData.put("name", new JSONString(username));
    postData.put("password", new JSONString(password));

    RestfulInvoker.invoke(RequestBuilder.POST, URLBuilder.getAuthenticationURL(), postData.toString(),
            callback);//from  ww  w. j  av  a  2 s .  c om
}

From source file:org.overlord.gadgets.web.client.presenter.LoginPresenter.java

License:Open Source License

public void registerUser(String username, String password, String email, String displayName,
        RestfulInvoker.Response callback) {

    JSONObject postData = new JSONObject();
    postData.put("name", new JSONString(username));
    postData.put("password", new JSONString(password));
    postData.put("email", new JSONString(email));
    postData.put("displayName", new JSONString(displayName));

    RestfulInvoker.invoke(RequestBuilder.POST, URLBuilder.getRegisterUserURL(), postData.toString(), callback);
}

From source file:org.overlord.gadgets.web.client.view.IndexViewImpl.java

License:Open Source License

@Inject
public IndexViewImpl(BootstrapContext ctx, CurrentUser user) {
    context = ctx;//from   www  .ja va2s. c  om
    currentUser = user;
    headerPanel = new LayoutPanel();
    headerPanel.setStyleName("header-panel");

    HTML logout = new HTML("Logout");
    logout.addStyleName("header-link");
    logout.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            RestfulInvoker.invoke(RequestBuilder.POST, URLBuilder.getInvalidSessionURL(), null,
                    new RestfulInvoker.Response() {
                        public void onResponseReceived(Request request, Response response) {
                            currentUser.setLoggedIn(false);
                            ApplicationEntryPoint.MODULES.getPlaceManager()
                                    .revealPlace(new PlaceRequest(NameTokens.LOGIN_VIEW));
                        }
                    });
        }
    });

    headerPanel.add(logout);

    headerPanel.setWidgetRightWidth(logout, 5, Style.Unit.PX, 60, Style.Unit.PX);
    headerPanel.setWidgetTopHeight(logout, 2, Style.Unit.PX, 28, Style.Unit.PX);

    Label userLabel = new Label(currentUser.getDisplayName());
    userLabel.setStyleName("userinfo");
    headerPanel.add(userLabel);

    headerPanel.setWidgetRightWidth(userLabel, 55, Style.Unit.PX, 150, Style.Unit.PX);
    headerPanel.setWidgetTopHeight(userLabel, 2, Style.Unit.PX, 28, Style.Unit.PX);

    HTML store = new HTML("Widget Store");
    store.addStyleName("header-link");
    store.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            if (currentUser.getCurrentPage() != 0) {
                ApplicationEntryPoint.MODULES.getPlaceManager()
                        .revealPlace(new PlaceRequest(NameTokens.WIDGET_STORE));
            } else {
                Window.alert("You need to create a Page before adding widgets from Widget Store!");
            }
        }
    });

    headerPanel.add(store);

    headerPanel.setWidgetRightWidth(store, 5, Style.Unit.PX, 110, Style.Unit.PX);
    headerPanel.setWidgetTopHeight(store, 45, Style.Unit.PX, 28, Style.Unit.PX);

    footerPanel = new LayoutPanel();
    footerPanel.setStyleName("footer-panel");

    panel = new DockLayoutPanel(Style.Unit.PX);
    panel.getElement().setAttribute("id", "container");

    mainContentPanel = new TabLayout(currentUser);

    final AddTabForm addTabForm = new AddTabForm(currentUser, mainContentPanel);

    Anchor anchor = new Anchor();
    anchor.setText("+");
    anchor.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent clickEvent) {
            addTabForm.show();
        }
    });
    mainContentPanel.setTabAnchor(anchor);

    mainPanel = new LayoutPanel();
    mainPanel.add(addTabForm);
    mainPanel.add(mainContentPanel);

    panel.addNorth(headerPanel, 70);
    panel.addSouth(footerPanel, 25);
    panel.add(mainPanel);

    footerPanel.add(ApplicationEntryPoint.MODULES.getFooter().asWidget());

}

From source file:org.overlord.gadgets.web.client.view.StoreViewImpl.java

License:Open Source License

@Inject
public StoreViewImpl(CurrentUser user) {

    this.currentUser = user;

    headerPanel = new LayoutPanel();
    headerPanel.setStyleName("header-panel");

    HTML logout = new HTML("Logout");
    logout.addStyleName("header-link");
    logout.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            RestfulInvoker.invoke(RequestBuilder.POST, URLBuilder.getInvalidSessionURL(), null,
                    new RestfulInvoker.Response() {
                        public void onResponseReceived(Request request, Response response) {
                            currentUser.setLoggedIn(false);
                            ApplicationEntryPoint.MODULES.getPlaceManager()
                                    .revealPlace(new PlaceRequest(NameTokens.LOGIN_VIEW));
                        }//w ww  .j ava2s  .com
                    });
        }
    });

    headerPanel.add(logout);

    headerPanel.setWidgetRightWidth(logout, 5, Style.Unit.PX, 60, Style.Unit.PX);
    headerPanel.setWidgetTopHeight(logout, 2, Style.Unit.PX, 28, Style.Unit.PX);

    Label userLabel = new Label(currentUser.getDisplayName());
    userLabel.setStyleName("userinfo");
    headerPanel.add(userLabel);

    headerPanel.setWidgetRightWidth(userLabel, 55, Style.Unit.PX, 150, Style.Unit.PX);
    headerPanel.setWidgetTopHeight(userLabel, 2, Style.Unit.PX, 28, Style.Unit.PX);

    HTML backToTabs = new HTML("Back to Tabs");
    backToTabs.addStyleName("header-link");
    backToTabs.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            ApplicationEntryPoint.MODULES.getPlaceManager()
                    .revealPlace(new PlaceRequest(NameTokens.INDEX_VIEW));
        }
    });

    headerPanel.add(backToTabs);

    headerPanel.setWidgetRightWidth(backToTabs, 5, Style.Unit.PX, 110, Style.Unit.PX);
    headerPanel.setWidgetTopHeight(backToTabs, 45, Style.Unit.PX, 28, Style.Unit.PX);

    footerPanel = new LayoutPanel();
    footerPanel.setStyleName("footer-panel");

    panel = new DockLayoutPanel(Style.Unit.PX);
    panel.getElement().setAttribute("id", "container");

    mainPanel = new LayoutPanel();
    mainPanel.getElement().setId("mainpanel");

    panel.addNorth(headerPanel, 70);
    panel.addSouth(footerPanel, 25);
    panel.add(mainPanel);

    footerPanel.add(ApplicationEntryPoint.MODULES.getFooter().asWidget());
}

From source file:org.overlord.gadgets.web.client.widgets.AddTabForm.java

License:Open Source License

public void addNewTab() {
    String name = tabName.getValue();
    String colNum = layoutColumns.getValue(layoutColumns.getSelectedIndex());

    Log.debug("the tab name is: " + name + ", and the colNum is: " + colNum + ", the userId : "
            + currentUser.getUserId());//from   www.j  a v a2s . co m

    JSONObject postData = new JSONObject();
    postData.put("name", new JSONString(name));
    postData.put("columns", new JSONNumber(Long.valueOf(colNum)));

    RestfulInvoker.invoke(RequestBuilder.POST, URLBuilder.getAddPageURL(currentUser.getUserId()),
            postData.toString(), new RestfulInvoker.Response() {

                public void onResponseReceived(Request request, Response response) {
                    Log.debug("The response is: " + response.getText() + ", and the currentUser is : "
                            + currentUser);
                    String newPageId = response.getText();
                    PortalLayout portal = new PortalLayout(newPageId,
                            Integer.valueOf(layoutColumns.getValue(layoutColumns.getSelectedIndex())));
                    tab.insertTab(newPageId, tabName.getValue(), portal);
                    tabName.setValue("");
                    currentUser.setCurrentPage(Long.valueOf(newPageId));
                }
            });

}

From source file:org.overlord.gadgets.web.client.widgets.Portlet.java

License:Open Source License

private Portlet(final String wid, final String pid) {
    widgetId = wid;/*w  ww . j  av a  2  s  .co m*/
    id = "portlet-" + widgetId;
    this.portalId = pid;
    this.iframeId = "iframe-" + widgetId;
    initWidget(uiBinder.createAndBindUi(this));

    getElement().setId(id);
    gadgetSpec.getElement().setId(iframeId);
    gadgetSpec.getElement().setAttribute("frameborder", "0");

    urlBase = getGadgetServerUrlBase();

    minBtn.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent clickEvent) {
            toggle(id);
        }
    });

    removeBtn.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent clickEvent) {
            if (Window.confirm("Are you sure to delete this widget?")) {
                String theURL = URLBuilder.getRemoveWidgetURL(Long.valueOf(widgetId));
                RestfulInvoker.invoke(RequestBuilder.POST, theURL, null, new RestfulInvoker.Response() {
                    public void onResponseReceived(Request request, Response response) {
                        remove(id);
                    }
                });
            }
        }
    });

    maxBtn.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            maximizeWindow(id, portalId);
            hideUserPref(id);
            showRestoreButton(id);
            gadgetSpec.setWidth("100%");
            gadgetSpec.setHeight("90%");
            gadgetSpec.getElement().setAttribute("scrolling", "auto");
            gadgetSpec.setUrl(urlBase + "gadget-server/gadgets/ifr?url=" + wmodel.getSpecUrl() + "&"
                    + getCanvasView() + "&" + userPreferenceValues);
        }
    });

    restoreBtn.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            restoreWindow(id);
            hideRestoreButton(id);
            gadgetSpec.setWidth("100%");
            gadgetSpec.setHeight("250px");
            gadgetSpec.getElement().setAttribute("scrolling", "auto");
            gadgetSpec.setUrl(urlBase + "gadget-server/gadgets/ifr?url=" + wmodel.getSpecUrl() + "&"
                    + getHomeView() + "&" + userPreferenceValues);
        }
    });

    settingBtn.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            showUserPref(id);
        }
    });

    gadgetSpec.getElement().setId(widgetId);
}