Fair enough. But I have use a Component, since AjaxSelfUpdatingTimerBehavioronly works on a component. Which means I have to implement the abstract onRender() method. What's the minimum action my onRender() needs to do, considering I just want an invisible component?
Or is there some other way to accomplish this automatic push of JavaScript without re-rendering the entire page on every update? From: Sven Meier <s...@meiers.net> To: users@wicket.apache.org Date: 05/06/2014 04:37 PM Subject: Re: AjaxSelfUpdatingTimerBehavior.onPostProcessTarget() Never Called By overriding #onRender() you're preventing the component tag to be written into the response. Since wicket-ajax cannot find the markuo id in the DOM, it will not perform the Ajax request. Sven On 05/06/2014 08:28 PM, Richard W. Adams wrote: > The onPostProcessTarget() method of my AjaxSelfUpdatingTimerBehavior is > not being called for some reason. Here's the code. I can see the start() > method being called (when the user clicks my "Start" button), but > onPostProcessTarget() is never invoked. What am I doing wrong? Do I need > to use some different sort of timer? > > //---------------------------------------------------------------------------------------------- > @Override protected void onRender(final MarkupStream stream) { > /* > * Does nothing. This component has no markup of its own. > * It exists only to update the progress bar. > */ > System.out.println("In ProgressBarUpdater.onRender()"); > stream.next(); // Keep Wicket from complaining about not > advancing the markup stream > } > //---------------------------------------------------------------------------------------------- > /** > * Opens the Ricola progress bar & begins the polling. We don't start > the polling until > * explicitly told to so do, for efficiency purposes. > * @param ajax The Ajax request wrapper. > * @param reporter The object to query for progress data. > */ > public void start(final AjaxRequestTarget ajax, final ProgressReporter > reporter) { > > final AjaxSelfUpdatingTimerBehavior behavior = new > AjaxSelfUpdatingTimerBehavior(Duration.seconds(2)) { > private static final long serialVersionUID = 1L; > > @Override protected void onPostProcessTarget(final > AjaxRequestTarget ajax) { > > System.out.printf("In onPostProcessTarget()"); > super.onPostProcessTarget(ajax); > final Progress progress = reporter.getProgress(); > final String script = // Build > script to update > ProgressScript.build(progress); // > progress bar > ajax.appendJavascript(script); > if (progress == null) { // > If operation is finished > final ProgressBarUpdater updater = > ProgressBarUpdater.this; > updater.remove(this); // > Stop timer to prevent > ajax.addComponent(updater); // pointless > polling > } > } > }; > add(behavior); > ajax.addComponent(this); > } > //---------------------------------------------------------------------------------------------- > > Here's the markup for the ProgressBarUpdater, the component to which these > methods belong: > > <span wicket:id="progress-updater"></span> > > > > From: Martin Grigorov <mgrigo...@apache.org> > To: "users@wicket.apache.org" <users@wicket.apache.org> > Date: 05/05/2014 03:32 PM > Subject: Re: Progress Bar > > > > Hi, > > > On Mon, May 5, 2014 at 7:18 PM, Richard W. Adams <rwada...@up.com> wrote: > >> We have a requirement to implement a progress bar for long-running > server >> operations. We can't use the code at >> https://github.com/wicketstuff/core/wiki/Progressbar, because it doesn't >> meet our corporate user interface look-and-feel standards. >> > Have you considered providing your own .css ? > https://github.com/wicketstuff/core/blob/wicket-6.x/jdk-1.6-parent/progressbar-parent/progressbar/src/main/java/org/wicketstuff/progressbar/ProgressBar.java#L109 > > > >> So, we started our own implementation. Our test page contains these >> methods below (the TestExecutor below class implements >> Callable<ExecutorResult>). >> >> >> > //---------------------------------------------------------------------------------------------- >> private Component createButton() { >> return new AjaxButton("start-button") { >> private static final long serialVersionUID = -1; >> >> @Override protected void onSubmit(final > AjaxRequestTarget >> ajax, final Form<?> form) { >> >> final ExecutorService service = Executors. >> newSingleThreadExecutor(); >> try { >> final ProgressBarTestPage page = >> ProgressBarTestPage.this; >> final TransactionData data = new >> TransactionData (page.getId(), false); >> final TestExecutor executor = new >> TestExecutor(data, getPermissions()); >> >> executor.addListener(page); // > Request >> notification when done >> future = service.submit(executor); // >> Begin execution >> progressBarUpdater.start(ajax, > executor); >> // Start polling for progress >> >> } catch (final Exception ex) { >> throw new RuntimeException(ex); >> } >> service.shutdown(); // Terminate gracefully >> (VM probably >> } // won't exit if we fail to do > this) >> }; >> } >> >> > //---------------------------------------------------------------------------------------------- >> /** >> Observer Pattern method to let us know when the task is done so we > can >> check how things went. >> */ >> @Override public void executionComplete(final EnmCallableExecutor >> executor) { >> >> try { >> if (!future.isCancelled()) { // >> Unless execution was canceled >> final ExecutorResult result = future.get(); // >> Get the outcome >> System.out.println(result); >> /* >> * TODO: Show success or error message >> */ >> } >> } catch (final Exception ex) { >> ex.printStackTrace(); >> } >> } >> >> The ProgessBarUpdater class has this method: >> >> >> > //---------------------------------------------------------------------------------------------- >> /** >> * Displays the progress bar & begins the polling. We don't start > the >> polling until >> * explicitly told to do, for efficiency purposes. >> * @param ajax The Ajax request wrapper. >> * @param reporter The object to query for progress data. >> */ >> public void start(final AjaxRequestTarget ajax, final ProgressReporter >> reporter) { >> >> add(new AjaxSelfUpdatingTimerBehavior(Duration.seconds(2)) { >> private static final long serialVersionUID = 1L; >> >> @Override protected void onPostProcessTarget(final >> AjaxRequestTarget ajax) { >> >> final Progress progress = > reporter.getProgress(); >> final String script = // Build >> script to update >> ProgressScript.build(progress); // >> progress bar >> ajax.appendJavascript(script); >> if (progress == null) { // If >> operation is finished >> final ProgressBarUpdater updater = >> ProgressBarUpdater.this; >> updater.remove(this); // >> Stop timer to prevent >> ajax.addComponent(updater); // > pointless >> polling >> } >> } >> }); >> ajax.addComponent(this); >> } >> >> The page also contains a Future object so we can check the result after >> the thread finishes: >> >> private Future<ExecutorResult> future; >> >> __________________________________________ >> >> Having said all that, here's the problem: When I click the page's > button, >> Wicket throws this error: >> >> Unable to serialize class: java.util.concurrent.FutureTask >> >> The FutureTask object, I believe, is coming from the service.submit call >> whose return value we store in our Future variable. >> >> Does anyone know how to get around this roadblock? >> >> >> >> ** >> >> This email and any attachments may contain information that is >> confidential and/or privileged for the sole use of the intended > recipient. >> Any use, review, disclosure, copying, distribution or reliance by > others, >> and any forwarding of this email or its contents, without the express >> permission of the sender is strictly prohibited by law. If you are not > the >> intended recipient, please contact the sender immediately, delete the >> e-mail and destroy all copies. >> ** >> > > > ** > > This email and any attachments may contain information that is confidential and/or privileged for the sole use of the intended recipient. Any use, review, disclosure, copying, distribution or reliance by others, and any forwarding of this email or its contents, without the express permission of the sender is strictly prohibited by law. If you are not the intended recipient, please contact the sender immediately, delete the e-mail and destroy all copies. > ** > --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org ** This email and any attachments may contain information that is confidential and/or privileged for the sole use of the intended recipient. Any use, review, disclosure, copying, distribution or reliance by others, and any forwarding of this email or its contents, without the express permission of the sender is strictly prohibited by law. If you are not the intended recipient, please contact the sender immediately, delete the e-mail and destroy all copies. **