Re: AjaxSelfUpdatingTimerBehavior.onPostProcessTarget() Never Called
I tried simplifying the design by extending AbstractAjaxTimerBehavior instead, but still can't get it to do anything. In the following class, the onTimer() method is never called: import org.apache.wicket.Component; import org.apache.wicket.ajax.AbstractAjaxTimerBehavior; import org.apache.wicket.ajax.AjaxRequestTarget; import org.apache.wicket.util.time.Duration; import com.uprr.eni.commons.util.progress.Progress; import com.uprr.eni.commons.util.progress.ProgressReporter; import com.uprr.eni.commons.util.progress.ProgressScript; //-- /** * Periodically sends JavaScript to the client to update the progress bar. */ public class ProgressUpdateBehavior extends AbstractAjaxTimerBehavior { private static final long serialVersionUID = 6685938921228093681L; private final ProgressReporter reporter; private final Component parent; //-- /** * Constructor. * @param reporter The object we will query for progress. * @param parent The component to which this behavior is attached. The behavior will remove * itself from the parent when {@code reporter.getProgress()} returns {@code null}. */ public ProgressUpdateBehavior(final ProgressReporter reporter, final Component parent) { super(Duration.seconds(2)); this.reporter = reporter; this.parent = parent; } //-- @Override protected void onTimer(final AjaxRequestTarget ajax) { final Progress progress = reporter.getProgress(); final String script = ProgressScript.build(progress); ajax.appendJavascript(script); if (progress == null) { parent.remove(this); } } //-- } I add the above behavior to the page when the user clicks a button to begin a long running task. I can see the background thread executing as expected, but the timer behavior's onTimer() is never executed. //-- 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 final Future future =// When/if task completes service.submit(executor); // Begin background thread BACKGROUND_TASKS.put(currentUserName, future);// Record what we're doing add(new ProgressUpdateBehavior(executor, this));// Start polling for progress } catch (final Exception ex) { throw new RuntimeException(ex); } service.shutdown(); } }; } From: Sven Meier 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()"); >
Re: AjaxSelfUpdatingTimerBehavior.onPostProcessTarget() Never Called
Some further info: I changed my class to extend Label instead of Component , and removed the onRender() override. But onPostProcessTarget() is still not called. Any suggestions would be greatly appreciated! From: Sven Meier 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: > > > > > > From: Martin Grigorov > To: "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 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). >> >> >> > //-- >> private Component createButton() { >> return new AjaxButton("start-button") { >> private static final long serialVersionUID = -1; >> >> @Override protected void onSubmit(final > AjaxRequestTarget >>
Re: AjaxSelfUpdatingTimerBehavior.onPostProcessTarget() Never Called
I finally got the onTimer() to execute. Had to change my button onclick() code to this: add(new ProgressUpdateBehavior(executor)); ajax.addComponent(this); It began working when I added the second line above. Without that, the client didn't receive the updated component with the new timer script. ** 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. **
Re: AjaxSelfUpdatingTimerBehavior.onPostProcessTarget() Never Called
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 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: > > > > > > From: Martin Grigorov > To: "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 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). >> >> >> > //-- >> private Component createButton() { >> return new Ajax
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: From: Martin Grigorov To: "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 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). //-- 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
AjaxSelfUpdatingTimerBehavior.onPostProcessTarget() Never Called
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: From: Martin Grigorov To: "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 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). > > > //-- > 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) > }; > } > > //-- > /** >Obse