Re: Update component after background thread is finished
Martin Grigorov-4 wrote Pastebin you code. While cleaning up the code to post it here I found a timer.stop() where it should not be. After removing it, everything works as it should do. That is, I create a new timer whenever the form is submitted, and add it to my textarea component. The timer starts working, as well as the background thread. When the latter is finished, I stop the timer and remove it from the textarea from within the timer's onTimer() method. I have noted that I need to stop the timer before I remove it. Otherwise I get the exception below. It is really not a problem to stop the timer, but since I am removing it anyway, I wonder if it should strictly be necessary to do it. Cheers, Humberto ERROR - DefaultExceptionMapper - Unexpected error occurred org.apache.wicket.WicketRuntimeException: Method onRequest of interface org.apache.wicket.behavior.IBehaviorListener targeted at com.telenor.claudia.web.gui.Index$StatusTimer@95ef17 on component [TextArea [Component id = feedbackPanel]] threw an exception at org.apache.wicket.RequestListenerInterface.internalInvoke(RequestListenerInterface.java:270) at org.apache.wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:241) at org.apache.wicket.request.handler.ListenerInterfaceRequestHandler.invokeListener(ListenerInterfaceRequestHandler.java:255) at org.apache.wicket.request.handler.ListenerInterfaceRequestHandler.respond(ListenerInterfaceRequestHandler.java:234) at org.apache.wicket.request.cycle.RequestCycle$HandlerExecutor.respond(RequestCycle.java:750) at org.apache.wicket.request.RequestHandlerStack.execute(RequestHandlerStack.java:64) at org.apache.wicket.request.cycle.RequestCycle.execute(RequestCycle.java:252) at org.apache.wicket.request.cycle.RequestCycle.processRequest(RequestCycle.java:209) at org.apache.wicket.request.cycle.RequestCycle.processRequestAndDetach(RequestCycle.java:280) at org.apache.wicket.protocol.http.WicketFilter.processRequest(WicketFilter.java:162) at org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:218) at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1084) at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:360) at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216) at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181) at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:726) at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405) at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152) at org.mortbay.jetty.Server.handle(Server.java:324) at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505) at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:829) at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:514) at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211) at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380) at org.mortbay.jetty.bio.SocketConnector$Connection.run(SocketConnector.java:228) at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:488) Caused by: java.lang.reflect.InvocationTargetException at sun.reflect.GeneratedMethodAccessor6.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.apache.wicket.RequestListenerInterface.internalInvoke(RequestListenerInterface.java:260) ... 25 more Caused by: java.lang.IllegalStateException: Behavior must be added to component before its id can be generated. Behavior: com.telenor.claudia.web.gui.Index$StatusTimer@95ef17, Component: org.apache.wicket.Behaviors@d91987 at org.apache.wicket.Behaviors.getBehaviorId(Behaviors.java:252) at org.apache.wicket.Component.getBehaviorId(Component.java:4436) at org.apache.wicket.Component.urlFor(Component.java:3292) at org.apache.wicket.behavior.AbstractAjaxBehavior.getCallbackUrl(AbstractAjaxBehavior.java:89) at org.apache.wicket.ajax.AbstractAjaxTimerBehavior.getCallbackScript(AbstractAjaxTimerBehavior.java:125) at org.apache.wicket.ajax.AbstractAjaxTimerBehavior.getJsTimeoutCall(AbstractAjaxTimerBehavior.java:118) at org.apache.wicket.ajax.AbstractAjaxTimerBehavior.respond(AbstractAjaxTimerBehavior.java:155) at org.apache.wicket.ajax.AbstractDefaultAjaxBehavior.onRequest(AbstractDefaultAjaxBehavior.java:316) ... 29 more -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/Update-component-after-background-thread-is-finished-tp4300126p4306383.html Sent from the Users forum mailing
Re: Update component after background thread is finished
Martin Grigorov-4 wrote On Wed, Jan 18, 2012 at 12:39 PM, humcasma lt;humcasma@gt; wrote: Martin Grigorov-4 wrote Pastebin you code. While cleaning up the code to post it here I found a timer.stop() where it should not be. After removing it, everything works as it should do. That is, I create a new timer whenever the form is submitted, and add it to my textarea component. The timer starts working, as well as the background thread. When the latter is finished, I stop the timer and remove it from the textarea from within the timer's onTimer() method. I have noted that I need to stop the timer before I remove it. Otherwise I get the exception below. It is really not a problem to stop the timer, but since I am removing it anyway, I wonder if it should strictly be necessary to do it. Cheers, Humberto ERROR - DefaultExceptionMapper - Unexpected error occurred org.apache.wicket.WicketRuntimeException: Method onRequest of interface org.apache.wicket.behavior.IBehaviorListener targeted at com.telenor.claudia.web.gui.Index$StatusTimer@95ef17 on component [TextArea [Component id = feedbackPanel]] threw an exception at org.apache.wicket.RequestListenerInterface.internalInvoke(RequestListenerInterface.java:270) at org.apache.wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:241) at org.apache.wicket.request.handler.ListenerInterfaceRequestHandler.invokeListener(ListenerInterfaceRequestHandler.java:255) at org.apache.wicket.request.handler.ListenerInterfaceRequestHandler.respond(ListenerInterfaceRequestHandler.java:234) at org.apache.wicket.request.cycle.RequestCycle$HandlerExecutor.respond(RequestCycle.java:750) at org.apache.wicket.request.RequestHandlerStack.execute(RequestHandlerStack.java:64) at org.apache.wicket.request.cycle.RequestCycle.execute(RequestCycle.java:252) at org.apache.wicket.request.cycle.RequestCycle.processRequest(RequestCycle.java:209) at org.apache.wicket.request.cycle.RequestCycle.processRequestAndDetach(RequestCycle.java:280) at org.apache.wicket.protocol.http.WicketFilter.processRequest(WicketFilter.java:162) at org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:218) at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1084) at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:360) at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216) at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181) at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:726) at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405) at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152) at org.mortbay.jetty.Server.handle(Server.java:324) at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505) at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:829) at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:514) at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211) at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380) at org.mortbay.jetty.bio.SocketConnector$Connection.run(SocketConnector.java:228) at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:488) Caused by: java.lang.reflect.InvocationTargetException at sun.reflect.GeneratedMethodAccessor6.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.apache.wicket.RequestListenerInterface.internalInvoke(RequestListenerInterface.java:260) ... 25 more Caused by: java.lang.IllegalStateException: Behavior must be added to component before its id can be generated. Behavior: com.telenor.claudia.web.gui.Index$StatusTimer@95ef17, Component: org.apache.wicket.Behaviors@d91987 at org.apache.wicket.Behaviors.getBehaviorId(Behaviors.java:252) at org.apache.wicket.Component.getBehaviorId(Component.java:4436) at org.apache.wicket.Component.urlFor(Component.java:3292) at org.apache.wicket.behavior.AbstractAjaxBehavior.getCallbackUrl(AbstractAjaxBehavior.java:89) at org.apache.wicket.ajax.AbstractAjaxTimerBehavior.getCallbackScript(AbstractAjaxTimerBehavior.java:125) at If you stop the timer behavior in onTimer() then #getJsTimeoutCall() wont be called at all. Check your code again and attach the debugger to see what happens. org.apache.wicket.ajax.AbstractAjaxTimerBehavior.getJsTimeoutCall(AbstractAjaxTimerBehavior.java:118) I consistently get the same problem. After the onTimer() method finishes, the focus of control goes
Re: Update component after background thread is finished
Martin Grigorov-4 wrote Yes. Just add both to the target when the data is available Well, I have now managed to get both the textarea updated while my background thread is running, and the dropdownchoice updated when the thread is finished. For that I use an AbstractAjaxTimerBehavior that I add to the textarea component (I guess I could also add it to my Page). Then, on the onTimer() method I add the textarea and/or the dropdownchoice to the target. So far, so good. The only problem now is that the timer is running all the time, even when I do not needed (i.e. even when the background thread is not running). I would like to start the timer when I launch the background thread and stop it when the thread is finished. I saw here (https://issues.apache.org/jira/browse/WICKET-1525) that there are plans to have a resettable timer. I tried to use the AbstractAjaxRestartableTimerBehavior class provided there, but I have encountered a problem. I create an AbstractAjaxRestartableTimerBehavior timer and add it to my Page. In the onTimer() method I check whether I have to update the textarea and the dropdownchoice and, if so, I add them to the target. If I find out that the background thread has finished, I also stop the timer (i.e. I stop the timer inside the onTimer() method). Everything works fine until I stop the timer. The onTimer() method finishes ok, but then I get an Access Denied message on the browser and the following warning: WARN - RequestListenerInterface - behavior not enabled; ignore call. Behavior test.web.gui.Index$1@17574b9 at component [Page class = test.web.gui.Index, id = 1, render count = 2] More details: My Page consists of a textarea, a timer and a form. The form contains the dropdownchoice. I have tried adding the timer to the textarea, but get the same error (but for the textarea component). I have tried submitting the form via Ajax and normally. Same error. Hope you know what the problem is and can help me. Cheers, Humberto -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/Update-component-after-background-thread-is-finished-tp4300126p4303428.html Sent from the Users forum mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: Update component after background thread is finished
Martin Grigorov-4 wrote If I understand you correctly then all you need is just timerBehavior.stop(). You don't need the restart functionality. You can also remove the behavior from the component and add new behavior instance later if you need it. Btw WICKET-1525 is implemented in Wicket 6.0 Then I did not explained me right :-). I have a form that invokes a lengthy process as a background thread when it is submitted. The form can be submitted many times. So I want the timer to start working when the form is submitted (and the thread is launched), and to stop working when the thread finishes. Using the resettable timer I get the previously mentioned error. I have now tried to add and remove the timer behavior as you said, but did not work, probably because my knowledge of Wicket is limited and I am doing something wrong. I have invoked textarea.add(timer) within the form's onSubmit(), and added textarea to the ajax's target. I also invoke textarea.remove(timer) within the timer's onTimer() method. Nothing happens (i.e. the Timer is not started). Cheers, Humberto -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/Update-component-after-background-thread-is-finished-tp4300126p4303675.html Sent from the Users forum mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Update component after background thread is finished
Hi, I have a simple form. When I submit it I launch a thread that runs on the background. When the thread is finished, I would like to update a DropdownChoice with the result generated by the thread. I manage to update the choice, but the changes are only visible when I refresh the page. To avoid that, I have used a AjaxEventBehavior to update the choice whenever the user clicks on it: serviceNameChoice = new DropDownChoiceString(serviceNameChoice, new ModelString(), serviceNames); serviceNameChoice.add(new AjaxEventBehavior(onclick) { protected void onEvent(AjaxRequestTarget target) { target.add(serviceNameChoice); } }); The result is an unusable drop-down choice, since the choice keep refreshing when I try to select a value. How can I do what I want, that is, update/refresh a DropdownChoice when a background thread finishes its work? Thanks! Humberto -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/Update-component-after-background-thread-is-finished-tp4300126p4300126.html Sent from the Users forum mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: Update component after background thread is finished
Igor Vaynberg-2 wrote start a timer behavior that polls and waits for the thread to finish, and only when its finished it updates the select. Thanks Igor. Yes, that is a solution that I have also considered and forgot to talk about. Indeed, I already have a timer behavior that I use to update a textarea with the status of the thread. But I would like to avoid having to timer behaviors. Could I have just one timer behavior that updates both the textarea and the dropdownchoice? Or any other solution? Humberto -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/Update-component-after-background-thread-is-finished-tp4300126p4301366.html Sent from the Users forum mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org