[ 
https://issues.apache.org/jira/browse/WICKET-1891?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Igor Vaynberg resolved WICKET-1891.
-----------------------------------

    Resolution: Fixed
      Assignee: Igor Vaynberg

> AjaxLazyLoadPanel shouldn't call getLoadingComponent(String) in constructor
> ---------------------------------------------------------------------------
>
>                 Key: WICKET-1891
>                 URL: https://issues.apache.org/jira/browse/WICKET-1891
>             Project: Wicket
>          Issue Type: Improvement
>          Components: wicket-extensions
>    Affects Versions: 1.4-M2
>            Reporter: Craig McIlwee
>            Assignee: Igor Vaynberg
>            Priority: Minor
>             Fix For: 1.4-M4
>
>
> 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;
> }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to