Uploaded image for project: 'Wicket'
  1. Wicket
  2. WICKET-556

Prevent setTimeout for AjaxSelfUpdatingTimerBehavior from firing after its contributing component has been replaced

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 1.3.0-beta1
    • 1.3.0-beta2
    • wicket
    • None

    Description

      Currently, the setTimeout for an AjaxTimerBehavior will fire after the contributing component has been replaced or removed through an ajax request. This will result in an exception server side and a full page refresh client side.

      One possible solution is to override getCallbackScript() to enclose the ajax callback in another function that will only execute the ajax request if the markup for the contributing component is still in the dom tree:

      protected CharSequence getCallbackScript(boolean recordPageVersion)
      {
      String mId = getComponent().getMarkupId();
      StringBuilder sb = new StringBuilder("exec_func(function() { ");
      sb.append("var el = wicketGet('" + mId + "'); ");
      sb.append("if(null != el)

      {"); sb.append(super.getCallbackScript(recordPageVersion)); sb.append("}

      ");
      sb.append("})");

      return sb.toString ();
      }

      Other options are to have the request cycle swallow the "component not found" exception for timer behaviors (since they will only fire 1 extra time)

      or

      a more complicated scheme would involve wicket actively managing javascript timer tokens client side so that they can be removed with clearTimeout when their contributing component is removed through an ajax request. The javascript to do this would be trivial (a simple container object mapping dom id to timer token), but the wicket lifecycle would need to support an onRemove callback for components to perform cleanup.

      Attachments

        Activity

          People

            knopp Matej Knopp
            jimmclaughlin Jim McLaughlin
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: