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

Reply via email to