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.freemedsoftware.gwt.client.widget.SupportModuleWidget.java

License:Open Source License

protected void loadSuggestions(String req, final Request r, final Callback cb) {
    if (req.length() < CurrentState.getMinCharCountForSmartSearch())
        return;/*  w  ww. j  a  v a  2  s.com*/
    if (Util.getProgramMode() == ProgramMode.STUBBED) {
        // Handle in a stubbed sort of way
        List<SuggestOracle.Suggestion> items = new ArrayList<SuggestOracle.Suggestion>();
        map.clear();
        addKeyValuePair(items, new String("Hackenbush, Hugo Z"), new String("1"));
        addKeyValuePair(items, new String("Firefly, Rufus T"), new String("2"));
        cb.onSuggestionsReady(r, new SuggestOracle.Response(items));
    } else if (Util.getProgramMode() == ProgramMode.JSONRPC) {

        RequestBuilder builder = null;
        if (hasAdditionalParameters) {
            String[] params = { moduleName, req, JsonUtil.jsonify(addParameters) };
            builder = new RequestBuilder(RequestBuilder.POST, URL.encode(Util.getJsonRequest(
                    "org.freemedsoftware.api.ModuleInterface.ModuleSupportPicklistMethod", params)));
        } else {
            String[] params = { moduleName, req };
            builder = new RequestBuilder(RequestBuilder.POST, URL.encode(Util.getJsonRequest(
                    "org.freemedsoftware.api.ModuleInterface.ModuleSupportPicklistMethod", params)));
        }

        try {
            builder.sendRequest(null, new RequestCallback() {
                public void onError(com.google.gwt.http.client.Request request, Throwable ex) {
                }

                @SuppressWarnings("unchecked")
                public void onResponseReceived(com.google.gwt.http.client.Request request,
                        com.google.gwt.http.client.Response response) {
                    if (Util.checkValidSessionResponse(response.getText())) {
                        if (200 == response.getStatusCode()) {
                            HashMap<String, String> result = (HashMap<String, String>) JsonUtil.shoehornJson(
                                    JSONParser.parseStrict(response.getText()), "HashMap<String,String>");
                            if (result != null) {
                                Set<String> keys = result.keySet();
                                Iterator<String> iter = keys.iterator();

                                List<SuggestOracle.Suggestion> items = new ArrayList<SuggestOracle.Suggestion>();
                                map.clear();
                                while (iter.hasNext()) {
                                    final String key = (String) iter.next();
                                    final String val = (String) result.get(key);
                                    addKeyValuePair(items, val, key);
                                }
                                cb.onSuggestionsReady(r, new SuggestOracle.Response(items));
                            } else // if no result then set value to 0
                                setValue(0);
                        } else {
                            GWT.log("Result " + response.getStatusText(), null);
                        }
                    }
                }
            });
        } catch (RequestException e) {
            GWT.log("Exception thrown: ", e);
        }
    } else {
        ModuleInterfaceAsync service = null;
        try {
            service = ((ModuleInterfaceAsync) Util
                    .getProxy("org.freemedsoftware.gwt.client.Api.ModuleInterface"));
        } catch (Exception e) {
        }

        service.ModuleSupportPicklistMethod(moduleName, req, new AsyncCallback<HashMap<String, String>>() {
            public void onSuccess(HashMap<String, String> result) {
                Set<String> keys = result.keySet();
                Iterator<String> iter = keys.iterator();

                List<SuggestOracle.Suggestion> items = new ArrayList<SuggestOracle.Suggestion>();
                map.clear();
                while (iter.hasNext()) {
                    final String key = (String) iter.next();
                    final String val = (String) result.get(key);
                    addKeyValuePair(items, val, key);
                }
                cb.onSuggestionsReady(r, new SuggestOracle.Response(items));
            }

            public void onFailure(Throwable t) {
                GWT.log("Exception thrown: ", t);
            }

        });
    }
}

From source file:org.freemedsoftware.gwt.client.widget.UserMultipleChoiceWidget.java

License:Open Source License

public void setValue(Integer[] values) {
    // In future, need to implement multiple resolve function so we don't
    // have to make a thousand RPC calls for a thousand entries. - Jeff

    // Clear current values in the widget
    clearValues();/*w w w  . j  a v a2 s . com*/

    // Loop through all values given
    for (int iter = 0; iter < values.length; iter++) {
        if (Util.getProgramMode() == ProgramMode.STUBBED) {
            addValue("Value " + new Integer(iter).toString(), new Integer(iter));
        } else if (Util.getProgramMode() == ProgramMode.JSONRPC) {
            final Integer i = new Integer(values[iter]);
            String[] params = { i.toString() };
            RequestBuilder builder = new RequestBuilder(RequestBuilder.POST,
                    URL.encode(Util.getJsonRequest("org.freemedsoftware.api.UserInterface.GetRecord", params)));
            try {
                builder.sendRequest(null, new RequestCallback() {
                    public void onError(com.google.gwt.http.client.Request request, Throwable ex) {
                        GWT.log("Exception", ex);
                    }

                    @SuppressWarnings("unchecked")
                    public void onResponseReceived(com.google.gwt.http.client.Request request,
                            com.google.gwt.http.client.Response response) {
                        if (200 == response.getStatusCode()) {
                            HashMap<String, String> result = (HashMap<String, String>) JsonUtil.shoehornJson(
                                    JSONParser.parseStrict(response.getText()), "HashMap<String,String>");
                            if (result != null) {
                                addValue(result.get("userdescrip"), i);
                            }
                        } else {
                            GWT.log(response.toString(), null);
                        }
                    }
                });
            } catch (RequestException e) {
                GWT.log("Exception", e);
            }
        } else {
            UserInterfaceAsync service = null;
            try {
                service = ((UserInterfaceAsync) Util
                        .getProxy("org.freemedsoftware.gwt.client.Api.UserInterface"));
            } catch (Exception e) {
            }
            final Integer i = new Integer(values[iter]);
            service.GetRecord(i, new AsyncCallback<HashMap<String, String>>() {
                public void onSuccess(HashMap<String, String> rec) {
                    addValue(rec.get("userdescrip"), i);
                }

                public void onFailure(Throwable t) {

                }
            });
        }
    }
}

From source file:org.freemedsoftware.gwt.client.widget.UserWidget.java

License:Open Source License

/**
 * Set value of current widget based on integer value, asynchronously.
 * /*from  ww  w . j av a  2s.co m*/
 * @param widgetValue
 */
public void setValue(Integer widgetValue) {
    value = widgetValue;
    if (Util.getProgramMode() == ProgramMode.STUBBED) {
        searchBox.setText("Stub Value");
        searchBox.setTitle("Stub Value");
    } else if (Util.getProgramMode() == ProgramMode.JSONRPC) {
        if (widgetValue.compareTo(0) == 0) {
            searchBox.setText("");
            searchBox.setTitle("");
        } else {
            String[] params = { widgetValue.toString() };
            RequestBuilder builder = new RequestBuilder(RequestBuilder.POST,
                    URL.encode(Util.getJsonRequest("org.freemedsoftware.api.UserInterface.GetRecord", params)));
            try {
                builder.sendRequest(null, new RequestCallback() {
                    public void onError(com.google.gwt.http.client.Request request, Throwable ex) {
                    }

                    @SuppressWarnings("unchecked")
                    public void onResponseReceived(com.google.gwt.http.client.Request request,
                            com.google.gwt.http.client.Response response) {
                        if (Util.checkValidSessionResponse(response.getText())) {
                            if (200 == response.getStatusCode()) {
                                HashMap<String, String> result = (HashMap<String, String>) JsonUtil
                                        .shoehornJson(JSONParser.parseStrict(response.getText()),
                                                "HashMap<String,String>");
                                if (result != null) {
                                    searchBox.setText(result.get("userdescrip"));
                                    searchBox.setTitle(result.get("userdescrip"));
                                }
                            } else {
                                Window.alert(response.toString());
                            }
                        }
                    }
                });
            } catch (RequestException e) {

            }
        }
    } else {
        UserInterfaceAsync service = null;
        try {
            service = ((UserInterfaceAsync) Util.getProxy("org.freemedsoftware.gwt.client.Api.UserInterface"));
        } catch (Exception e) {
        }

        service.GetRecord(widgetValue, new AsyncCallback<HashMap<String, String>>() {
            public void onSuccess(HashMap<String, String> r) {
                searchBox.setText(r.get("userdescrip"));
                searchBox.setTitle(r.get("userdescrip"));
            }

            public void onFailure(Throwable t) {

            }
        });

    }
}

From source file:org.freemedsoftware.gwt.client.widget.UserWidget.java

License:Open Source License

protected void loadSuggestions(String req, final Request r, final Callback cb) {
    if (req.length() < CurrentState.getMinCharCountForSmartSearch())
        return;/*ww w  .j a  v a 2s .c om*/
    if (Util.getProgramMode() == ProgramMode.STUBBED) {
        // Handle in a stubbed sort of way
        List<SuggestOracle.Suggestion> items = new ArrayList<SuggestOracle.Suggestion>();
        map.clear();
        addKeyValuePair(items, new String("Hackenbush, Hugo Z"), new String("1"));
        addKeyValuePair(items, new String("Firefly, Rufus T"), new String("2"));
        cb.onSuggestionsReady(r, new SuggestOracle.Response(items));
    } else if (Util.getProgramMode() == ProgramMode.JSONRPC) {

        RequestBuilder builder = null;
        if (userType.equals("")) {
            String[] params = { req };
            builder = new RequestBuilder(RequestBuilder.POST,
                    URL.encode(Util.getJsonRequest("org.freemedsoftware.api.UserInterface.GetUsers", params)));
        } else {
            String[] params = { req, userType };
            builder = new RequestBuilder(RequestBuilder.POST,
                    URL.encode(Util.getJsonRequest("org.freemedsoftware.api.UserInterface.GetUsers", params)));
        }
        try {
            builder.sendRequest(null, new RequestCallback() {
                public void onError(com.google.gwt.http.client.Request request, Throwable ex) {
                }

                public void onResponseReceived(com.google.gwt.http.client.Request request,
                        com.google.gwt.http.client.Response response) {
                    if (Util.checkValidSessionResponse(response.getText())) {
                        if (200 == response.getStatusCode()) {
                            String[][] result = (String[][]) JsonUtil
                                    .shoehornJson(JSONParser.parseStrict(response.getText()), "String[][]");
                            if (result != null) {
                                List<SuggestOracle.Suggestion> items = new ArrayList<SuggestOracle.Suggestion>();
                                map.clear();
                                for (int iter = 0; iter < result.length; iter++) {
                                    String[] x = result[iter];
                                    final String key = x[1];
                                    final String val = x[0];
                                    addKeyValuePair(items, val, key);
                                }
                                cb.onSuggestionsReady(r, new SuggestOracle.Response(items));
                            }
                        } else {
                            GWT.log("Result " + response.getStatusText(), null);
                        }
                    }
                }
            });
        } catch (RequestException e) {
            GWT.log("Exception thrown: ", e);
        }
    } else {
        UserInterfaceAsync service = null;
        try {
            service = ((UserInterfaceAsync) Util.getProxy("org.freemedsoftware.gwt.client.Api.UserInterface"));
        } catch (Exception e) {
        }

        service.GetUsers(req, new AsyncCallback<String[][]>() {
            public void onSuccess(String[][] result) {
                List<SuggestOracle.Suggestion> items = new ArrayList<SuggestOracle.Suggestion>();
                map.clear();
                for (int iter = 0; iter < result.length; iter++) {
                    String[] x = result[iter];
                    final String key = x[1];
                    final String val = x[0];
                    addKeyValuePair(items, val, key);
                }
                cb.onSuggestionsReady(r, new SuggestOracle.Response(items));
            }

            public void onFailure(Throwable t) {
                GWT.log("Exception thrown: ", t);
            }

        });
    }
}

From source file:org.freemedsoftware.gwt.client.widget.UserWidget.java

License:Open Source License

@Override
public void getTextForValue(Integer val) {
    if (Util.getProgramMode() == ProgramMode.STUBBED) {
        searchBox.setText("Hackenbush, Hugo Z (STUB)");
    } else if (Util.getProgramMode() == ProgramMode.JSONRPC) {
        String[] params = { val.toString() };
        RequestBuilder builder = new RequestBuilder(RequestBuilder.POST,
                URL.encode(Util.getJsonRequest("org.freemedsoftware.api.UserInterface.GetRecord", params)));
        try {/*from   w ww .j av  a 2 s. c  om*/
            builder.sendRequest(null, new RequestCallback() {
                public void onError(com.google.gwt.http.client.Request request, Throwable ex) {
                }

                @SuppressWarnings("unchecked")
                public void onResponseReceived(com.google.gwt.http.client.Request request,
                        com.google.gwt.http.client.Response response) {
                    if (Util.checkValidSessionResponse(response.getText())) {
                        if (200 == response.getStatusCode()) {
                            HashMap<String, String> result = (HashMap<String, String>) JsonUtil.shoehornJson(
                                    JSONParser.parseStrict(response.getText()), "HashMap<String,String>");
                            if (result != null) {
                                searchBox.setText(result.get("userdescrip"));
                            }
                        } else {
                            GWT.log("Result " + response.getStatusText(), null);
                        }
                    }
                }
            });
        } catch (RequestException e) {
            GWT.log("Exception thrown: ", e);
        }
    } else {
        UserInterfaceAsync service = null;
        try {
            service = ((UserInterfaceAsync) Util.getProxy("org.freemedsoftware.gwt.client.Api.UserInterface"));
        } catch (Exception e) {
        }
        service.GetRecord(val, new AsyncCallback<HashMap<String, String>>() {
            public void onSuccess(HashMap<String, String> r) {
                searchBox.setText(r.get("userdescrip"));
            }

            public void onFailure(Throwable t) {
                GWT.log("Exception", t);
            }
        });
    }
}

From source file:org.freemedsoftware.gwt.client.widget.WorkList.java

License:Open Source License

private void changeStatus(Widget w1, Widget w2, String appid, String patid, String st, int i) {
    final int index = i;
    final Widget wDisplay = w1;
    final Widget wHide = w2;
    final String statusid = st;
    HashMap<String, String> map = new HashMap<String, String>();
    map.put((String) "cspatient", patid);
    map.put((String) "csappt", appid);
    map.put((String) "csstatus", st);
    JsonUtil.debug("before saving");
    String[] params = { JsonUtil.jsonify(map) };
    RequestBuilder builder = new RequestBuilder(RequestBuilder.POST,
            URL.encode(Util.getJsonRequest("org.freemedsoftware.module.SchedulerPatientStatus.add", params)));

    try {/*  w w  w .ja v a2s  .  c  o m*/
        builder.sendRequest(null, new RequestCallback() {
            public void onError(Request request, Throwable ex) {
            }

            public void onResponseReceived(Request request, Response response) {

                if (200 == response.getStatusCode()) {
                    wHide.setVisible(false);
                    wDisplay.setVisible(true);
                    int currRow = workListsTables[index].getActionRow();
                    workListsTables[index].getFlexTable().getRowFormatter().getElement(currRow).getStyle()
                            .setProperty("backgroundColor", statusColorsMap.get(statusid));

                } else {
                    Util.showErrorMsg("Patient Status", _("Patient status change failed."));

                    // printLabelForAllTakeHome();
                }
            }
        });
    } catch (RequestException e) {

    }

}

From source file:org.freemedsoftware.gwt.client.widget.WorkList.java

License:Open Source License

public void populateStatus() {

    if (Util.getProgramMode() == ProgramMode.STUBBED) {

    } else if (Util.getProgramMode() == ProgramMode.JSONRPC) {
        String[] params = {};/*w  w  w  . j  a v a  2 s. c o m*/
        RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL.encode(
                Util.getJsonRequest("org.freemedsoftware.module.SchedulerStatusType.getStatusType", params)));
        try {
            builder.sendRequest(null, new RequestCallback() {
                public void onError(com.google.gwt.http.client.Request request, Throwable ex) {
                }

                @SuppressWarnings("unchecked")
                public void onResponseReceived(com.google.gwt.http.client.Request request,
                        com.google.gwt.http.client.Response response) {
                    if (Util.checkValidSessionResponse(response.getText())) {
                        if (200 == response.getStatusCode()) {
                            HashMap<String, String>[] result = (HashMap<String, String>[]) JsonUtil
                                    .shoehornJson(JSONParser.parseStrict(response.getText()),
                                            "HashMap<String,String>[]");
                            if (result != null) {
                                statusNamesMap = new HashMap<String, String>();
                                statusColorsMap = new HashMap<String, String>();
                                for (int i = 0; i < result.length; i++) {
                                    statusNamesMap.put(result[i].get("Id"), result[i].get("descp"));
                                    statusColorsMap.put(result[i].get("Id"), result[i].get("status_color"));
                                }

                            } else {
                            }
                        } else {
                            GWT.log("Result " + response.getStatusText(), null);
                        }
                    }
                }
            });
        } catch (RequestException e) {
            GWT.log("Exception thrown: ", e);
        }
    } else {

    }
}

From source file:org.freemedsoftware.gwt.client.widget.WorkList.java

License:Open Source License

public void retrieveData() {
    vPanel.add(paneltop);/*from  w  ww . jav a 2s  .c o m*/
    vPanel.add(message);
    if (CurrentState.getDefaultProvider() == 0) {
        providerGroupId = CurrentState.defaultProviderGroup;
        if (Util.getProgramMode() == ProgramMode.JSONRPC) {
            String[] params = { providerGroupId.toString() };
            RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL.encode(
                    Util.getJsonRequest("org.freemedsoftware.module.ProviderGroups.getProviderIds", params)));
            try {
                builder.sendRequest(null, new RequestCallback() {
                    public void onError(com.google.gwt.http.client.Request request, Throwable ex) {
                        Window.alert(ex.toString() + "error1");

                    }

                    public void onResponseReceived(com.google.gwt.http.client.Request request,
                            com.google.gwt.http.client.Response response) {
                        if (200 == response.getStatusCode()) {
                            if (Util.checkValidSessionResponse(response.getText())) {
                                String provs[] = (String[]) JsonUtil
                                        .shoehornJson(JSONParser.parseStrict(response.getText()), "String[]");
                                if (provs != null) {
                                    if (provs.length != 0) {
                                        providers = new Integer[provs.length];
                                        workListsTables = new CustomTable[provs.length];
                                        providersLb = new Label[provs.length];
                                        for (int i = 0; i < provs.length; i++) {
                                            providers[i] = new Integer(provs[i]);
                                            getProviderInfo(i);
                                        }
                                    } else {

                                    }
                                }

                            }
                        } else {
                            Window.alert(response.toString() + "error2");
                        }
                    }
                });
            } catch (RequestException e) {
                Window.alert(e.toString());
            }

        } else {
        }
    } else {
        providers = new Integer[1];
        workListsTables = new CustomTable[1];
        providersLb = new Label[1];
        providers[0] = new Integer(CurrentState.getDefaultProvider());
        getProviderInfo(0);
    }
}

From source file:org.freemedsoftware.gwt.client.widget.WorkList.java

License:Open Source License

private void getProviderInfo(int i) {
    final int index = i;
    providersLb[i] = new Label();
    providersLb[i].setVisible(false);/*from   www. j a va 2  s .c o m*/
    providersLb[i].getElement().getStyle().setProperty("cursor", "pointer");
    providersLb[i].getElement().getStyle().setProperty("fontWeight", "bold");
    providersLb[i].getElement().getStyle().setProperty("textDecoration", "underline");
    providersLb[i].getElement().getStyle().setProperty("verticalAlign", "middle");
    providersLb[i].setHeight("20");
    providersLb[i].addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent e) {
            if (workListsTables[index].isVisible()) {
                workListsTables[index].setVisible(false);
            } else {
                workListsTables[index].setVisible(true);
            }
        }
    });
    if (Util.getProgramMode() == ProgramMode.JSONRPC) {
        String[] params = { "" + providers[i] };
        RequestBuilder builder = new RequestBuilder(RequestBuilder.POST,
                URL.encode(Util.getJsonRequest("org.freemedsoftware.module.ProviderModule.fullName", params)));
        try {
            builder.sendRequest(null, new RequestCallback() {
                public void onError(com.google.gwt.http.client.Request request, Throwable ex) {
                    Window.alert(ex.toString() + "error1");

                }

                public void onResponseReceived(com.google.gwt.http.client.Request request,
                        com.google.gwt.http.client.Response response) {
                    if (200 == response.getStatusCode()) {
                        if (Util.checkValidSessionResponse(response.getText())) {
                            String provInfo = (String) JsonUtil
                                    .shoehornJson(JSONParser.parseStrict(response.getText()), "String");
                            if (provInfo != null) {
                                providersLb[index].setText(provInfo);
                                createWorkListTableForProvider(index);
                            }

                        }
                    } else {
                        Window.alert(response.toString() + "error2");
                    }
                }
            });
        } catch (RequestException e) {
            Window.alert(e.toString());
        }

    } else {
    }
}

From source file:org.freemedsoftware.gwt.client.widget.WorkList.java

License:Open Source License

private void retrieveData(int i) {
    final int index = i;
    if ((providerGroupId != null && providerGroupId != 0) || CurrentState.getDefaultProvider() > 0) {
        if (Util.getProgramMode() == ProgramMode.STUBBED) {

        } else if (Util.getProgramMode() == ProgramMode.JSONRPC) {
            // JSON-RPC
            String[] params = { "" + providers[i] };
            RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL.encode(Util
                    .getJsonRequest("org.freemedsoftware.module.WorkListsModule.GenerateWorkList", params)));
            try {
                builder.sendRequest(null, new RequestCallback() {
                    public void onError(Request request, Throwable ex) {
                        Util.showErrorMsg("WorkLists", _("Failed to get work list."));
                    }//from   w  w  w .  j a v  a2 s . c  o  m

                    @SuppressWarnings("unchecked")
                    public void onResponseReceived(Request request, Response response) {
                        if (200 == response.getStatusCode()) {

                            try {
                                if (response.getText().compareToIgnoreCase("null") != 0
                                        && response.getText().compareTo("[[]]") != 0
                                        && response.getText().compareToIgnoreCase("false") != 0) {
                                    HashMap<String, String>[] r = (HashMap<String, String>[]) JsonUtil
                                            .shoehornJson(JSONParser.parseStrict(response.getText()),
                                                    "HashMap<String,String>[]");
                                    // Window.alert(r[0].toString());
                                    if (r != null) {
                                        if (r.length > 0) {

                                            // workListsTables[index].setVisible(true);
                                            if (r.length >= 10)
                                                workListsTables[index].setMaximumRows(10);
                                            else
                                                workListsTables[index].setMaximumRows(r.length);
                                            VerticalPanel vp = new VerticalPanel();
                                            vp.add(providersLb[index]);
                                            vp.add(workListsTables[index]);
                                            tablesVPanel.add(vp);

                                            providersLb[index].setVisible(true);
                                            // workListsTables[index].setVisible(true);
                                            workListsTables[index].loadData(r);
                                        }
                                    }
                                } else {

                                }
                            } catch (Exception ex) {

                            }
                        } else {
                            Util.showErrorMsg("WorkLists", _("Failed to get work list."));
                        }
                    }
                });
            } catch (RequestException e) {
                Util.showErrorMsg("WorkLists", _("Failed to get work list."));
            }
        } else {
            // GWT-RPC
        }
    } else {
        // workListTable.setVisible(false);
        providerLabel.setVisible(true);
        providerLabel.setText(_("Provider not available."));
    }
}