0

我一定错过了一些简单的东西,但我被卡住了。我在gwt中创建了一个FormPanel,根据firebug发送请求。该链接有效,因为我从 firebug 复制了 requestlink 并在浏览器窗口中进行了本地尝试。是的,客户端和服务器主机是相同的 --> localhost。但答案并没有到达 gwt。甚至客户端浏览器都没有——萤火虫没有显示任何结果。

这是我的小表格:

    Button form = new Button ("SendForm", new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            logger.log(Level.FINER, "Creating SubmitForm...");

            TextBox cmd = new TextBox();
            cmd.setName("cmd");
            cmd.setText("GetMenuitemList");

            Button sendbutton = new Button("Senden");
            logger.log(Level.FINEST, "Creating grid...");
            Grid grid = new Grid(1, 2);
            grid.setWidget(0, 0, new  Label("Command"));
            grid.setWidget(0, 1, cmd);

            VerticalPanel vPan = new VerticalPanel();
            //vPan.add(grid);
            vPan.add(sendbutton);

            logger.log(Level.FINEST, "Creating FormPanel...");
            final FormPanel formPan = new FormPanel();
            formPan.setMethod(FormPanel.METHOD_POST);
            formPan.setAction(RequestHelper.getLink("Menu.php"));

            logger.log(Level.FINEST, "Binding Send button...");
            logger.log(Level.FINEST, "Binding SubmitHandler...");
            formPan.addSubmitHandler(new SubmitHandler() {

                @Override
                public void onSubmit(SubmitEvent event) {
                    OptionPane.showMessageDialog("Form submit", event.toDebugString(), MessageType.INFO, true);
                }
            });

            logger.log(Level.FINEST, "Binding SubmitCompleteHandler...");
            formPan.addSubmitCompleteHandler(new SubmitCompleteHandler() {

                @Override
                public void onSubmitComplete(SubmitCompleteEvent event) {
                    OptionPane.showMessageDialog("Form SubmitComplete", event.toDebugString(), MessageType.INFO, true);
                }
            });

            logger.log(Level.FINEST, "Adding grid to formpan...");
            formPan.add(grid);
            formPan.add(vPan);

            logger.log(Level.FINEST, "Creating DialogBox...");
            final DialogBox box = OptionPane.createClosableBox("TestForm", true);

            sendbutton.addClickHandler(new ClickHandler() {

                @Override
                public void onClick(ClickEvent event) {
                    formPan.submit();
                    box.hide();
                }
            });

            box.add(formPan);
            box.center();
        }
    });

预期的答案如下所示:

{"sessionid":"6dbqibo25e0bn46fldqh37psj5","data":[{"title":"Start","Controller":"Start","Action":"Index","tooltip":"Startseite, Begr\u00fc\u00dfung","prefetch":"1"},{"title":"Register","Controller":"Person","Action":"Index","tooltip":"Neue Benutzer registrieren","prefetch":"0"},{"title":"Daten","Controller":"Contact","Action":"Index","tooltip":"Die eigenen Daten bearbeiten","prefetch":"1"},{"title":"Teilnehmerlisten","Controller":"Lists","Action":"Index","tooltip":"Listen der registrierten Benutzer","prefetch":"0"},{"title":"Suche","Controller":"Search","Action":"Index","tooltip":"Namenssuche nach Benutzer mit Kontaktm\u00f6glichkeit","prefetch":"1"},{"title":"Kalender","Controller":"Calendar","Action":"Index","tooltip":"Termine","prefetch":"1"},{"title":"Newsletter","Controller":"Newsletter","Action":"Index","tooltip":"Verschicken von Newslettern","prefetch":"1"},{"title":"Wettk\u00e4mpfer","Controller":"Competitor","Action":"Index","tooltip":"Zugriff auf Wettk\u00e4mpfer","prefetch":"1"},{"title":"Upload","Controller":"Upload","Action":"Index","tooltip":"Bilder, Videos o.\u00e4. hochladen","prefetch":"0"},{"title":"Administration","Controller":"Admin","Action":"Index","tooltip":"Datenbankfunktionen und Benutzerrechte","prefetch":"1"}]}

那么,这里出了什么问题?

顺便说一句,我会将这种技术用于登录表单。我读到,以表格形式执行此操作比通过 RequestBuilder (已经有效)更好。文件上传将在稍后进行,因此表单问题无论如何都需要答案...

先感谢您。马库斯

编辑:好的,我也在 Chromium、Konqueror 和 Opera 上进行了测试——代码有效。这只是火狐。让它与Firefox一起使用的想法?我是 eclipse 和 gwt 的新手……也许是一些编译器选项?

4

1 回答 1

0

我自己发现并解决了问题:form.submit执行后,我隐藏了表单面板。正如javadoc所说,这是不允许的:

在提交完成之前,不得将 FormPanel 分离(即从其父级移除或以其他方式与 RootPanel 断开连接)。否则,提交通知将失败。

于 2013-03-27T14:44:15.853 回答