I have created a addon to refresh a component at regular frequency (initiated from the client side using gwt Timer), this addon works well for a while, however after a few mins it gets in to trouble… below is the console msgs from the debug window…
13:09:32:372 Retrieved a hierarchy update for a connector (1166) that is not a ComponentContainerConnector
.... above err msg repeated multiple times....
13:09:32:373 Retrieved a hierarchy update for a connector (1183) that is not a ComponentContainerConnector
13:09:32:376 * Update of connector hierarchy completed: 23 ms
13:09:32:376 * Sending hierarchy change events
13:09:32:394 ClassCastException
13:09:32:427 ClassCastException
.... above err msg repeated multiple times....
13:09:32:670 ClassCastException
13:09:32:677 ClassCastException
13:09:32:695 * Hierarchy state change event processing completed: 319 ms
13:09:32:704 * Sending state change events
13:09:32:752 ClassCastException
13:09:32:787 ClassCastException
13:09:32:795 JavaScriptException: (TypeError): Cannot read property 'e' of null
13:09:32:802 JavaScriptException: (TypeError): Cannot read property 'e' of null
13:09:32:809 JavaScriptException: (TypeError): Cannot read property 'e' of null
13:09:32:816 ClassCastException
13:09:32:823 ClassCastException
13:09:32:831 JavaScriptException: (TypeError): Cannot read property 'e' of null
13:09:32:838 JavaScriptException: (TypeError): Cannot read property 'e' of null
... above err msg repeated multiple times....
13:09:33:424 ClassCastException
13:09:33:429 Parent of connector HorizontalLayoutConnector (1263) is null. This is typically an indication of a broken component hierarchy
13:09:33:432 Parent of connector HorizontalLayoutConnector (1265) is null. This is typically an indication of a broken component hierarchy
13:09:33:434 ClassCastException
13:09:33:440 ClassCastException
13:09:33:447 ClassCastException
... above err msg repeated multiple times....
And below is code for the addon
Server side component:
public class Refresher extends AbstractComponent {
private int milliseconds;
public interface UpdateHandler extends Serializable {
public void update();
}
private UpdateHandler updateHandler = null;
public UpdateRPC rpc = new UpdateRPC() {
@Override
public void update() {
updateHandler.update();
}
};
public Refresher() {
registerRpc(rpc);
}
public void setMilliseconds(int milliseconds) {
this.milliseconds = milliseconds;
getState().setMilliseconds(milliseconds);
requestRepaint();
}
@Override
protected RefresherState createState() {
return new RefresherState(this.milliseconds);
}
@Override
public RefresherState getState() {
return (RefresherState) super.getState();
}
public void setUpdateHandler(UpdateHandler updateHandler) {
this.updateHandler = updateHandler;
}
public UpdateHandler getUpdateHandler() {
return updateHandler;
}
}
Connector:
@Connect(Refresher.class)
public class RefresherConnector extends AbstractComponentConnector {
private UpdateRPC rpc;
public interface UpdateRPC extends ServerRpc {
public void update();
}
@Override
public void init() {
rpc = RpcProxy.create(UpdateRPC.class, this);
VRefresher widget = getWidget();
widget.setUpdateHandler(new UpdateHandler() {
@Override
public void update() {
rpc.update();
}
});
}
@Override
public RefresherState getState() {
return (RefresherState) super.getState();
}
@Override
protected Widget createWidget() {
return GWT.create(VRefresher.class);
}
@Override
public VRefresher getWidget() {
return (VRefresher) super.getWidget();
}
@Override
public void onStateChanged(StateChangeEvent stateChangeEvent) {
super.onStateChanged(stateChangeEvent);
getWidget().setMilliseconds(getState().getMilliseconds());
}
}
State:
public class RefresherState extends ComponentState {
private int milliseconds;
public RefresherState() {
}
public RefresherState(int milliseconds) {
this.milliseconds = milliseconds;
}
public int getMilliseconds() {
return milliseconds;
}
public void setMilliseconds(int milliseconds) {
this.milliseconds = milliseconds;
}
}
Client:
public class VRefresher extends Widget {
/** Set the CSS class name to allow styling. */
public static final String CLASSNAME = "v-mycomponent";
private Timer timer;
// /** The client side widget identifier */
// protected String paintableId;
// /** Reference to the server connection object. */
// ApplicationConnection client;
/**
* The constructor should first call super() to initialize the component and
* then handle any initialization relevant to Vaadin.
*/
public VRefresher() {
// TODO Example code is extending GWT Widget so it must set a root
// element.
// Change to proper element or remove if extending another widget
setElement(Document.get().createDivElement());
// This method call of the Paintable interface sets the component
// style name in DOM tree
setStyleName(CLASSNAME);
timer = createTimer();
}
private Timer createTimer() {
Timer timer = new Timer() {
@Override
public void run() {
update();
}
};
return timer;
}
private void update() {
updateHandler.update();
}
private int milliseconds;
public int getMilliseconds() {
return milliseconds;
}
public void setMilliseconds(int milliseconds) {
this.milliseconds = milliseconds;
timer.scheduleRepeating(milliseconds);
}
private UpdateHandler updateHandler = null;
public interface UpdateHandler extends Serializable {
public void update();
}
public void setUpdateHandler(UpdateHandler updateHandler) {
this.updateHandler = updateHandler;
}
public UpdateHandler getUpdateHandler() {
return updateHandler;
}
}
And this is how this addon is added as a component
Refresher refresher = new Refresher();
refresher.setUpdateHandler(new UpdateHandler() {
@Override
public void update() {
//refresh();//do the update stuffs here...
}
});
refresher.setMilliseconds(120000);
addComponent(refresher);
Not sure about the cause of the issue, any advice on this will be really helpful.