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 <[email protected]> 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: [email protected] > For additional commands, e-mail: [email protected] > > --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
