You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by "Brown, Berlin [GCG-PFS]" <Be...@Primerica.com> on 2010/10/06 15:20:00 UTC

Initialization/Business Logic code before page loads

I might have asked a similar question in a previous post but I wanted to
clarify a bit.
 
Where is the best place to put code to initialize the model before a
page renders.  I know of five options, but where do you normally put
this type of initialization.
 
Before a page renders, I want to set the data in my bean/model with
certain attributes that may only be specific to that page. 
 
I think there are five options.
 
1. Add initialization logic in the constructor.  This may work, but I
don't know if the constructor is called for every page call (E.g. when
the page is deserialized)
2. Add init logic in onBeforeRender.  This works and it called for every
request?  But is it the best place?
3. Add init logic in a "load" or "getmodel" method in
LoadableDetachableModel class?
4. Add init in previous page on onSubmit method or onEvent. (onSubmit()
{ initBeanInSession(); setResponsePage(); }
5. Pass a model to a panel or page constructor (using pageparameters?)
 
Are any of these best practices or preferred over the other.
 
(a) Page Constructor code with Loadable detachable model:
 
MyPage.java:
...
final Form<MyBean> form = new Form<MyBean>(FORM, new
CompoundPropertyModel<MyBean>(new LoadableDetachableModel<MyBean>() {
   
   private static final long serialVersionUID = 1L;
   @Override
   protected MyBean load() {    
    final MyBean app = (MyBean) Session.get().getApp();

    ?????????????
    ?????????????
    initialize here???????
    ?????????????
    return app;
   }   
  };
});
 
???
onBeforeRender() {
   ?? Add initiailize here   
   final MyBean app = (MyBean) Session.get().getApp();
   app.setData(doSomeBusinessLogicHere)
   
}
 
or initModel?
 
-------
 
 
 
 
Berlin Brown

Re: Initialization/Business Logic code before page loads

Posted by Igor Vaynberg <ig...@gmail.com>.
and if you need it called before *every* render, there is component#onconfigure

-igor

On Wed, Oct 6, 2010 at 6:39 AM, Michael O'Cleirigh
<mi...@rivulet.ca> wrote:
>  Hello,
>
> There is a sixth option, look at Component.onInitialize() which was added
> recently (in July 2010) to 1.4.x which lets you initialize the component
> after it has been added to the page.
>
> If you need to access state in the page and aren't passing a model through
> to your component this would be something to investigate.
>
> Regards,
>
> Mike
>
>> I might have asked a similar question in a previous post but I wanted to
>> clarify a bit.
>>
>> Where is the best place to put code to initialize the model before a
>> page renders.  I know of five options, but where do you normally put
>> this type of initialization.
>>
>> Before a page renders, I want to set the data in my bean/model with
>> certain attributes that may only be specific to that page.
>>
>> I think there are five options.
>>
>> 1. Add initialization logic in the constructor.  This may work, but I
>> don't know if the constructor is called for every page call (E.g. when
>> the page is deserialized)
>> 2. Add init logic in onBeforeRender.  This works and it called for every
>> request?  But is it the best place?
>> 3. Add init logic in a "load" or "getmodel" method in
>> LoadableDetachableModel class?
>> 4. Add init in previous page on onSubmit method or onEvent. (onSubmit()
>> { initBeanInSession(); setResponsePage(); }
>> 5. Pass a model to a panel or page constructor (using pageparameters?)
>>
>> Are any of these best practices or preferred over the other.
>>
>> (a) Page Constructor code with Loadable detachable model:
>>
>> MyPage.java:
>> ...
>> final Form<MyBean>  form = new Form<MyBean>(FORM, new
>> CompoundPropertyModel<MyBean>(new LoadableDetachableModel<MyBean>() {
>>
>>    private static final long serialVersionUID = 1L;
>>    @Override
>>    protected MyBean load() {
>>     final MyBean app = (MyBean) Session.get().getApp();
>>
>>     ?????????????
>>     ?????????????
>>     initialize here???????
>>     ?????????????
>>     return app;
>>    }
>>   };
>> });
>>
>> ???
>> onBeforeRender() {
>>    ?? Add initiailize here
>>    final MyBean app = (MyBean) Session.get().getApp();
>>    app.setData(doSomeBusinessLogicHere)
>>
>> }
>>
>> or initModel?
>>
>> -------
>>
>>
>>
>>
>> Berlin Brown
>>
>
>
> ---------------------------------------------------------------------
> 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: Initialization/Business Logic code before page loads

Posted by Michael O'Cleirigh <mi...@rivulet.ca>.
  Hello,

There is a sixth option, look at Component.onInitialize() which was 
added recently (in July 2010) to 1.4.x which lets you initialize the 
component after it has been added to the page.

If you need to access state in the page and aren't passing a model 
through to your component this would be something to investigate.

Regards,

Mike

> I might have asked a similar question in a previous post but I wanted to
> clarify a bit.
>
> Where is the best place to put code to initialize the model before a
> page renders.  I know of five options, but where do you normally put
> this type of initialization.
>
> Before a page renders, I want to set the data in my bean/model with
> certain attributes that may only be specific to that page.
>
> I think there are five options.
>
> 1. Add initialization logic in the constructor.  This may work, but I
> don't know if the constructor is called for every page call (E.g. when
> the page is deserialized)
> 2. Add init logic in onBeforeRender.  This works and it called for every
> request?  But is it the best place?
> 3. Add init logic in a "load" or "getmodel" method in
> LoadableDetachableModel class?
> 4. Add init in previous page on onSubmit method or onEvent. (onSubmit()
> { initBeanInSession(); setResponsePage(); }
> 5. Pass a model to a panel or page constructor (using pageparameters?)
>
> Are any of these best practices or preferred over the other.
>
> (a) Page Constructor code with Loadable detachable model:
>
> MyPage.java:
> ...
> final Form<MyBean>  form = new Form<MyBean>(FORM, new
> CompoundPropertyModel<MyBean>(new LoadableDetachableModel<MyBean>() {
>
>     private static final long serialVersionUID = 1L;
>     @Override
>     protected MyBean load() {
>      final MyBean app = (MyBean) Session.get().getApp();
>
>      ?????????????
>      ?????????????
>      initialize here???????
>      ?????????????
>      return app;
>     }
>    };
> });
>
> ???
> onBeforeRender() {
>     ?? Add initiailize here
>     final MyBean app = (MyBean) Session.get().getApp();
>     app.setData(doSomeBusinessLogicHere)
>
> }
>
> or initModel?
>
> -------
>
>
>
>
> Berlin Brown
>


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