Search code examples
htmlformsgwthttp-postformpanel

Receiving data from a FormPanel in GWT


I have a FormPanel in GWT that should send a TextBox input to a new page (newPage.html). Below is my code. How do I receive this input in newPage.html, so that I can work with it from the associate newPage.java class? Thanks

final FormPanel form = new FormPanel();
form.setEncoding(FormPanel.ENCODING_MULTIPART);
form.setMethod(FormPanel.METHOD_POST);

TextBox userid = new TextBox();
userid.setName("userid");
form.add(userid);

form.add(new Button("Submit", new ClickListener()
{    
    public void onClick(Widget sender)
    {
        form.submit();
    }
}));

form.setAction("newPage.html");
RootPanel.get("demo").add(form);

Solution

  • If what you are trying to do is POST variables from one gwt-page using a formpanel to another gwt-page to process these POST results you can not, simply because gwt-pages are coded with java but in the end they are translated into javascript and javascript alone can not access POST variables.

    You need to define a backend that can process your form in your form.setAction() method that should execute on the server-side and produce a valid html/text response. To get these results produced by your backend you need to add a FormHandler to your FormPanel. There is an example showing how to do that on javadocs. Then evaluating these results you can redirect accordingly.

    If you want to handle what you send with a java class meaning you have a java backend, why not use GWT-RPC?