You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Henrique Boregio <hb...@gmail.com> on 2009/04/13 02:56:15 UTC

Refreshing page / onBeforeRender() issue

I have a web page with a simple design where a NavigationPanel
contains a few links which replace the main panel with other panels.

My problem is that when I initialize this web page, it creates all of
the panels which will eventually replace a main panel (according to
the link in the NavigationPanel that the user has clicked) by calling
their constructors. Since the constructors initialize a bunch of
components and also retrieve data from a database, it takes a "long"
time to render the web page since it is also loading all of the other
panels.

Since I want to perform a kind of lazy loading (I only load the
components of the panels if the user has clicked on the corresponding
link in the NavigationPanel), I moved the code where I initialize the
components to the onBeforeRender() method instead of the constructor.
It worked fine for the first time I clicked a link but if I re-clicked
it, a wicket error would pop up since I was trying to add new
components that had already been added.

My solution was something like:

protected void onBeforeRender() {
  super.onBeforeRender();
		
  if(!firstTime) {
     return;
  }

  // create the components used in this panel
  ...
  firstTime = true
}


This way the components are created only if it is the first time I am
loading the panel.

My question is, is there a better or automatic way of doing this through wicket?
Thanks.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Refreshing page / onBeforeRender() issue

Posted by Igor Vaynberg <ig...@gmail.com>.
not exactly

everytime you click you would do:

{contentpanel.replace(newpanel); contentpanel=newpanel; }

the last line: contentpanel=newpanel; frees up the reference to the
old panel which will be garbage collected

-igor

On Sun, Apr 12, 2009 at 8:55 PM, quiqueq <hb...@gmail.com> wrote:
>
>
> How can I be sure that there is only 1 instance of somepanel? If the user
> clicks 10 times the link, 10 different panels would be created in memory.
>
>
> igor.vaynberg wrote:
>>
>> you should only create the panels when the user clicks on the link
>>
>> add(new link(..) {
>>  onclick() {
>>    panel=new somepanel(...);
>>    ((mypage)getpage()).setcontentpanel(panel);
>>   }
>> }
>>
>> -igor
>>
>
> --
> View this message in context: http://www.nabble.com/Refreshing-page---onBeforeRender%28%29-issue-tp23016450p23017567.html
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Refreshing page / onBeforeRender() issue

Posted by quiqueq <hb...@gmail.com>.

How can I be sure that there is only 1 instance of somepanel? If the user
clicks 10 times the link, 10 different panels would be created in memory.


igor.vaynberg wrote:
> 
> you should only create the panels when the user clicks on the link
> 
> add(new link(..) {
>  onclick() {
>    panel=new somepanel(...);
>    ((mypage)getpage()).setcontentpanel(panel);
>   }
> }
> 
> -igor
> 

-- 
View this message in context: http://www.nabble.com/Refreshing-page---onBeforeRender%28%29-issue-tp23016450p23017567.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Refreshing page / onBeforeRender() issue

Posted by Igor Vaynberg <ig...@gmail.com>.
you should only create the panels when the user clicks on the link

add(new link(..) {
 onclick() {
   panel=new somepanel(...);
   ((mypage)getpage()).setcontentpanel(panel);
  }
}

-igor

On Sun, Apr 12, 2009 at 5:56 PM, Henrique Boregio <hb...@gmail.com> wrote:
> I have a web page with a simple design where a NavigationPanel
> contains a few links which replace the main panel with other panels.
>
> My problem is that when I initialize this web page, it creates all of
> the panels which will eventually replace a main panel (according to
> the link in the NavigationPanel that the user has clicked) by calling
> their constructors. Since the constructors initialize a bunch of
> components and also retrieve data from a database, it takes a "long"
> time to render the web page since it is also loading all of the other
> panels.
>
> Since I want to perform a kind of lazy loading (I only load the
> components of the panels if the user has clicked on the corresponding
> link in the NavigationPanel), I moved the code where I initialize the
> components to the onBeforeRender() method instead of the constructor.
> It worked fine for the first time I clicked a link but if I re-clicked
> it, a wicket error would pop up since I was trying to add new
> components that had already been added.
>
> My solution was something like:
>
> protected void onBeforeRender() {
>  super.onBeforeRender();
>
>  if(!firstTime) {
>     return;
>  }
>
>  // create the components used in this panel
>  ...
>  firstTime = true
> }
>
>
> This way the components are created only if it is the first time I am
> loading the panel.
>
> My question is, is there a better or automatic way of doing this through wicket?
> Thanks.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org