“No RequestCycle is currently set!” exception when using icepush wicket integration and trying to call 'push()' from another class

StackOverflow https://stackoverflow.com/questions/9842788

Question

Ok here goes. This is my first ever wicket application and I'm trying to integrate icepush using the pushpanel example.

What I'm trying to do is push an update to the panel by calling an 'updatePanel(String content)' method from another class.

Here is the code.

In my extended PushPanel I have:

public AsyncCommsPanel(String id) {
    super(id);
    this.setOutputMarkupId(true);

    ajaxForm = new Form("ajaxForm");
    ajaxForm.setOutputMarkupId(true);

    ajaxForm.add(textStore = new Label("textStore",""));

    ajaxForm.add(new AjaxButton("updateButton") {
        @Override
        protected void onSubmit(AjaxRequestTarget target, Form form) {
            System.out.println("Update button pressed!");
            /* CODE TO PULL NEW DATA FROM ELSEWHERE */
            /* UPDATE TAKES TIME SO HAS ITS OWN CALLBACK */
        }

        @Override
        protected void onError(AjaxRequestTarget target, Form<?> form) {
            System.out.println("Update button error.");
        }
    });
    add(ajaxForm);
}

@Override
protected void pushCallback(AjaxRequestTarget target) {
    target.add(ajaxForm);
}

public void updatePanel(String updateString) {
    /* THIS METHOD SHOULD ALLOW THE PANEL TO BE UPDATED FROM ELSEWHERE */
    if (textStore != null) ajaxForm.remove(textStore);
    ajaxForm.add(textStore = new Label("textStore", updateString));
    push();
}

When I try to call the 'updatePanel' method from the data gatherer's callback method, I get this exception:

ERROR (SelectorManager.run):  org.apache.wicket.WicketRuntimeException: No RequestCycle is currently set!
at org.apache.wicket.Component.getRequest(Component.java:1831)
at org.apache.wicket.markup.html.WebPage.dirty(WebPage.java:315)
at org.apache.wicket.Page.dirty(Page.java:288)
at org.apache.wicket.Page.componentRemoved(Page.java:948)
at org.apache.wicket.MarkupContainer.removedComponent(MarkupContainer.java:1422)
at org.apache.wicket.MarkupContainer.remove(MarkupContainer.java:612)
at uk.ac.warwick.collabtex.AsyncCommsPanel.updatePanel(AsyncCommsPanel.java:107)
at uk.ac.warwick.collabtex.Editor$1.updateSuccess(Editor.java:98)
Was it helpful?

Solution

Welcome to the asynchronous world :-) The ThreadLocals (Application, Session and ThreadLocal) are available only during the processing of a http request thread (aka worker thread). So there are two problems: 1) by starting your own thread you lose the ThreadLocal's, 2) even if you export them then there is a chance that the Response will be already closed when your job finish. I'm not sure how IcePush works but here is what I think is the best option - submit the task, keep a reference to it in the Application (e.g. a Map) and then start an ajax timer behavior which asks futureTask.isDone() periodically and when it returns true do the hierarchy changes you need (I see a call to MarkupContainer#remove() in the stacktrace).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top