Vaadin:无法在com.vaadin.shared.ui.button.ButtonServerRpc中调用方法点击

时间:2013-12-11 20:19:47

标签: java tomcat vaadin

我正在尝试将浮点值转换为vaadin中的int值,但是当我在文本字段中插入内容并单击按钮时出现此错误(错误消息显示在按钮的上下文菜单中):< / p>

com.vaadin.server.ServerRpcManager $ RpcInvocationException:无法在com的com.vaadin.server.ServerRpcManager.applyInvocation(ServerRpcManager.java:170)的com.vaadin.shared.ui.button.ButtonServerRpc中调用方法单击。 vaadin.server.ServerRpcManager.applyInvocation(ServerRpcManager.java:118)at com.vaadin.server.communication.ServerRpcHandler.handleBurst(ServerRpcHandler.java:207)

等等。

这是我的Java代码:

package com.eduwallchart.schulung2;

import javax.servlet.annotation.WebServlet;

import com.vaadin.annotations.Theme;
import com.vaadin.annotations.VaadinServletConfiguration;
import com.vaadin.server.VaadinRequest;
import com.vaadin.server.VaadinServlet;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Label;
import com.vaadin.ui.TextField;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;

@Theme("mytheme")
@SuppressWarnings("serial")
public class MyVaadinUI extends UI {

    @WebServlet(value = "/*", asyncSupported = true)
    @VaadinServletConfiguration(productionMode = false, ui = MyVaadinUI.class, widgetset = "com.eduwallchart.schulung2.AppWidgetSet")
    public static class Servlet extends VaadinServlet {
    }

    @Override
    protected void init(VaadinRequest request) {
        final VerticalLayout layout = new VerticalLayout();
        layout.setMargin(true);
        setContent(layout);

        Button button = new Button("Convert Float to Int");
        final TextField textfield = new TextField("Int-Wert:");
        Label label = new Label("0.0");
        button.addClickListener(new Button.ClickListener() {

            public void buttonClick(ClickEvent event) {
                float floatValue;
                String intValue;
                floatValue = (Float) textfield.getData();
                intValue = String.valueOf(floatValue);
                textfield.setCaption(intValue);
            }
        });

        layout.addComponent(textfield);
        layout.addComponent(button);

    }

}

我在NetBeans 7.4中运行代码,而我正在使用本地TomCat服务器(在IDE中)。

1 个答案:

答案 0 :(得分:0)

好的,我自己找到了答案。它必须是:

public void buttonClick(ClickEvent event) {
    floatValue = Float.parseFloat(textfield.getValue());
    intValue = Math.round(floatValue);
    stringValue = String.valueOf(intValue);
    textfield.setCaption(stringValue);
}