ServerRpc无法在自定义Vaadin Widgetset中工作,为什么我会得到" Widgetset' ...'不包含' ...&#39 ;?的实施

时间:2015-01-24 20:07:39

标签: gwt widget vaadin rpc

我对Vaadin中的ServerRpc实现有疑问,我在eclipse中有一个带有widgetset的简单示例项目:

以下是课程:

widgetpackage.MarqueeLabel:

public class MarqueeLabel extends AbstractComponent {




/**

     * 

     */

private static final long serialVersionUID = 1L;



@Override

public MarqueeLabelState getState() {

       return (MarqueeLabelState) super.getState();

    }



@Override

public void setCaption(String caption) {

       getState().text = caption;

    } 




}

widgetpackage.WidgetUI:

public class WidgetUI extends UI {




@WebServlet(value = "/*", asyncSupported = true)

@VaadinServletConfiguration(productionMode = false, ui = WidgetUI.class, widgetset = "widgetpackage.widgetWidgetset")

public static class Servlet extends VaadinServlet {

    }




@Override

protected void init(VaadinRequest request) {

        final VerticalLayout layout = new VerticalLayout();

        layout.setMargin(true);

        setContent(layout);




        MarqueeLabel label = new MarqueeLabel();

        label.setCaption("Hello I am custom widget!");



        layout.addComponent(label);

    }




}

widgetpackage.client.MarqeeLabelWidget:

public class MarqueeLabelWidget extends Label {




    public MarqueeLabelWidget() {

            final Element el = getElement();

            el.getStyle().setPosition(Position.RELATIVE);



            Timer timer = new Timer() {

                private int left = 0;



                @Override

                public void run() {

                    el.getStyle().setLeft(left, Unit.PX);

                    left++;

                }

            };

            timer.scheduleRepeating(100);

        }



    }

widgetpackage.client.MarqueeLabelState: 

public class MarqueeLabelState extends AbstractComponentState {




/**

     * 

     */

private static final long serialVersionUID = 1L;




public String text;



}

widgetpackage.client.MarqueeLabelConnector:

@Connect(MarqueeLabel.class)

public class MarqueeLabelConnector extends AbstractComponentConnector {




/**

     * 

     */

private static final long serialVersionUID = 1L;




@Override

public Widget createWidget() {

        return GWT.create(MarqueeLabelWidget.class);

    }



@Override

public MarqueeLabelWidget getWidget() {

        return (MarqueeLabelWidget) super.getWidget();

    }



@Override

public MarqueeLabelState getState() {

        return (MarqueeLabelState) super.getState();

    }



    @Override

    public void onStateChanged(StateChangeEvent e) {

            super.onStateChanged(e);

            getWidget().setText(getState().text);

        }



    }

WidgetWidgetset.gwt.xml位于widgetpackage包中:

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 1.7.0//EN" "http://google-web-toolkit.googlecode.com/svn/tags/1.7.0/distro-source/core/src/gwt-module.dtd">

<module>

    <inherits name="com.vaadin.DefaultWidgetSet" />

</module>

当我构建widgetset并在服务器上运行时#39;一切正常,但是当我添加这个ServerRpc实现时,就像这样:

1)添加widgetpackage.MarqueeLabelServerRpc接口(widgetpackage,MarqueeLabel服务器组件所在的位置):

 public interface MarqueeLabelServerRpc extends ServerRpc {

      public void clicked();

    }

2)将这些行添加到widgetpackage.client.MarqueeLabelConnector:

public class MarqueeLabelConnector extends AbstractComponentConnector {

  private MarqueeLabelServerRpc rpc = RpcProxy.create(
      MarqueeLabelServerRpc.class, this);

  public MarqueeLabelConnector() {
    getWidget().addClickHandler(new ClickHandler() {
      @Override
      public void onClick(ClickEvent event) {
        rpc.clicked(); // server's call
      }
    });
  }

  // ...

}

3)这个构造函数到widgetpackage.MarqueeLabel: 公共类MarqueeLabel扩展了AbstractComponent {

  public MarqueeLabel() {
    registerRpc(new MarqueeLabelServerRpc() {
      @Override
      public void clicked() {
        Notification.show("Made a RPC”); 
      }
    });
  }

  // ...

}

如果我重新编译widgetset并运行项目,我会在浏览器中看到它:

  

Widgetset&#39; widgetpackage.widgetWidgetset&#39;不含   实现&#39; widgetpackage.MarqueeLabel&#39;。检查其组件   连接器的@Connect映射,widgetsets GWT模块描述文件   并重新编译您的widgetset。如果你下载了vaadin   附加软件包,您可能需要参考附加说明。

为什么当我添加RPC实现时,widgetset不再能找到MarqueeLabel的实现?

1 个答案:

答案 0 :(得分:0)

我已经解决了,问题是MarqueeLabelServerRpc需要在widgetpackage.client包中,而不是widgetpackage。