Details
-
Improvement
-
Status: Resolved
-
Trivial
-
Resolution: Duplicate
-
1.3.5, 1.4-M3, 1.5-M1
-
None
-
None
-
All
Description
My use case is: I have a page with an AjaxSelfUpdatingTimerBehavior and a button that opens a modal window. If the modal window is opened and the timer fires the refresh, the browser ask for a confirmation to leave the page, and then closes the modal window.
It would be very nice to be able to stop the self updating behavior just before opening the modal window, and restarting it just before closing it. This feature has already been requested long ago in SourceForge tracker, see: http://www.nabble.com/forum/ViewPost.jtp?post=5773807&framed=y, but couldn't find it in JIRA.
To overcome this problem, I created a custom (AbstractAjax + AjaxSelfUpdating)TimerBehavior, and added this method:
/**
- Starts the timer
*/
public final void start(final AjaxRequestTarget target) { stopped = false; target.getHeaderResponse().renderOnLoadJavascript( getJsTimeoutCall(updateInterval)); }
And changed (this might not be important, I'm not sure but this works for me):
/**
*
- @see org.apache.wicket.ajax.AbstractDefaultAjaxBehavior#respond(org.apache.wicket.ajax.AjaxRequestTarget)
*/
protected final void respond(final AjaxRequestTarget target)
{
onTimer(target);
if (!stopped)
{ target.getHeaderResponse().renderOnLoadJavascript( getJsTimeoutCall(updateInterval)); }}
to:
/**
*
- @see org.apache.wicket.ajax.AbstractDefaultAjaxBehavior#respond(org.apache.wicket.ajax.AjaxRequestTarget)
*/
protected final void respond(final AjaxRequestTarget target)
{
if (!stopped) { onTimer(target); target.getHeaderResponse().renderOnLoadJavascript( getJsTimeoutCall(updateInterval)); }
}
Then in the onClick of the button that opens the modal window, I call;
@Override
public void onClick(AjaxRequestTarget target) {
autoRefreshBehavior.stop();
//---
and in the onClose of the modal window:
@Override
public void onClose(AjaxRequestTarget target)
It's working fine so far, but it would be nice to have this little feature or something similar provided in core.
Attachments
Issue Links
- duplicates
-
WICKET-1525 Ability to enable/disable AbstractAjaxTimerBehavior
- Resolved