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

AjaxLazyLoadPanel shouldn't call getLoadingComponent(String) in constructor

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • 1.4-M2
    • 1.4-RC1
    • wicket-extensions
    • None

    Description

      Use case:

      class MyPanel extends AjaxLazyLoadPanel {
      private boolean bool;

      public MyPanel(String id, boolean bool)

      { super(id); <-- bool is used in this call this.bool = bool; <-- but not assigned until this call }

      public getLoadingComponent(String id) {
      if (bool)

      { return componentA; }

      else

      { return componentB; }

      }
      }


      Since getLoadingComponent(String) is called as part of the super constructor then the actual value of 'bool' can never be used. Furthur, if bool were an object instead of a primitive could potentially cause an NPE. Instead the loading component can be created in onBeforeRender():

      protected void onBeforeRender() {
      if (!renderedOnce)

      { loadingComponent = getLoadingComponent("content"); add(loadingComponent.setRenderBodyOnly(true)); renderedOnce = true; }

      super.onBeforeRender();
      }

      ... this also requires a change to the ajax behavior:

      public boolean isEnabled(Component<?> component) {
      return get("content") == loadingComponent || loadingComponent == null;
      }

      Attachments

        Activity

          People

            ivaynberg Igor Vaynberg
            falcor Craig McIlwee
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: