Hi everyone, I have a question about the ServerRpc implemetation in Vaadin, I have a simple example project in eclipse with a widgetset:
Here are the classes:
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
:
[code]
@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);
}
}
[/code]the
WidgetWidgetset.gwt.xml
is located in the
widgetpackage
package:
[code]
<?xml version="1.0" encoding="UTF-8"?><inherits name="com.vaadin.DefaultWidgetSet" />
[/code]When I build the widgetset and 'Run on server' everything works fine, but then when I add this ServerRpc implementation, like this:
- Add the
widgetpackage.MarqueeLabelServerRpc
interface (widgetpackage, where MarqueeLabel server component is located):
[code]
public interface MarqueeLabelServerRpc extends ServerRpc {
public void clicked();
}
[/code]2) Add this lines to the
widgetpackage.client.MarqueeLabelConnector
:
[code]
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
}
});
}
// …
}
[/code]3) And this constructor to the
widgetpackage.MarqueeLabel
:
public class MarqueeLabel extends AbstractComponent {
public MarqueeLabel() {
registerRpc(new MarqueeLabelServerRpc() {
@Override
public void clicked() {
Notification.show("Made a RPC”);
}
});
}
// ...
}
If I recompile the widgetset and run the project, I get this in the browser:
Widgetset ‘widgetpackage.widgetWidgetset’ does not contain implementation for ‘widgetpackage.MarqueeLabel’. Check its component connector’s @Connect mapping, widgetsets GWT module description file and re-compile your widgetset. In case you have downloaded a vaadin add-on package, you might want to refer to add-on instructions.
Why when I add the RPC implementation, the widgetset doesn’t find the implementation of MarqueeLabel anymore?